When using the count(const) algorithm in STL, an error operator not found which takes a left operand of type 'const _Ty' occurred.
The reason is that the custom doubly linked list class did not overload the left operator ==. Adding the overload operation fixes it.
Author: Broccoli
Copyright Notice: All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
Related Articles
2021-08-06
c++ 单独使用remove_if造成数据重复的问题
在使用remove_if时发现此函数无法对容器内满足pred表达式的数据删除,remove_if将会使用列表内其他数据填充,而本身的大小不变,具体解释可以参考remove_if的用法,这种情况下需要搭配erase方法彻底删除. 12bool IsMoreThen(LinkList target){return target.count>=5;}list.erase(std::remove_if(list.begin(), list.end(), IsMoreThen)); 原因remove_if方法是找出符合条件的元素,并使用erase删除返回的vector<_type_>::iterator 的值,并将元素跳转向下一个元素,此时由于元素指针自动跳转+1,会造成连续值删除出现漏删的情况,针对这种情况需要写一个方法重新计算即可。 1234567891011std::vector<LinkList> RemovePredList(std::vector<LinkList> lists){ std::vec...
2020-06-14
C++ primer&primerPlus笔记
一C++ primerplus第六章分支语句是看到一个案例, 1234567891011121314151617181920212223242526272829 char ch; cout << "Typr , and I shell repeat.\n"; cin.get(ch); while (ch != '.') { if (ch == '\n') cout << ch; else cout << ch +1; cin.get(ch); } cout << "\n Please excuse thr slight confusion.\n";``` 其中我们将``cout<<ch+1``替换为``cout<<++ch``之后会出现两个不同的- ch+1 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071// ConsoleApplication1.cpp : This file contains the "main" function. Program execution begins and ends here.//#include <iostream>#include <string>#include <io.h>#include <sstream>std::string chToH...
2021-08-06
Issue with C++ remove_if causing data duplication
When using remove_if, I found that this function cannot delete data in the container that satisfies the pred expression. remove_if will use other data in the list to fill, while the size itself remains unchanged. For specific explanation, refer to Usage of remove_if. In this case, you need to use the erase method to completely delete it. 12bool IsMoreThen(LinkList target){return target.count>=5;}list.erase(std::remove_if(list.begin(), list.end(), IsMoreThen)); ReasonThe remove_i...

2020-12-31
C++ Virtual Inheritance
I used to study C++ for a while, but never found a suitable project to get familiar with it. So I am learning C++ following an open source project on github, address: github 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647/* * Virtual Inheritance * Concept: Solves the data inconsistency problem caused by different copies of the same data member inherited from different paths in memory. * Set the common base class as a virtual base class. * At this time, t...
2020-12-02
C++ 获取文件夹下所有文件并修改为16进制名
参考连接:https://blog.csdn.net/u012500825/article/details/41947013C++ 字符、字符串转十六进制(支持中文字符串转换) 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include <string>#include <io.h>#include <sstream>std::string chToHex(unsigned char ch){ const std::string hex = "0123456789ABCDEF"; std::st...
Announcement
欢迎访问!右上角可切换中英文。感谢您的阅读!

