使用STL的find函数遇到的问题
来源:互联网 发布:数据库概论第五版答案 编辑:程序博客网 时间:2024/06/06 03:57
先查了下资料 http://www.cplusplus.com/reference/algorithm/find/
Example
/ find example#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;int main ()
{ int myints[] = { 10, 20, 30 ,40 }; int * p; // pointer to array element: p = find(myints,myints+4,30); ++p; cout << "The element following 30 is " << *p << endl; vector<int> myvector (myints,myints+4); vector<int>::iterator it; // iterator to vector element: it = find (myvector.begin(), myvector.end(), 30); ++it; cout << "The element following 30 is " << *it << endl; return 0;}
Output:
The element following 30 is 40The element following 30 is 40
但是自己的project 编译完了报错Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const std::basic_string<_Elem,_Traits,_Alloc>' (or there is no acceptable conversion) c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility 3171
一直找不到错误 很纠结。后来在http://stackoverflow.com/questions/8792110/stdsetstring-customcomparer-cannot-use-stdfind-with里看到类似的,可能是==没处理,而且是string的==
后来解决方式很雷人---加了#include<string.h>就可以了
国内的网上我没有搜到这个error,希望遇到这个问题的孩子们节省点时间 呵呵
数组和list都可以实现:
数组 string Funlist[343]={。。。。。。}
string *p = find(Funlist, Funlist + 342, strTmp);
if (p == Funlist + 342)
{
strItemName = prefix + Substr ;
}
else
{ //not adfin
strItemName = prefix1 + Substr;
}
不过数组一定不要越界了
使用容器
list<string>::iterator it;
it = find(vecList.begin(),vecList.end(),strTmp);
/*cout << strTmp.c_str() << endl;
_getch();*/
//if (it == vecList.end())
// {
// strItemName = prefix + Substr ;
// }
// else
// { //not adfin
// strItemName = prefix1 + Substr;
// }
- 使用STL的find函数遇到的问题
- python find 遇到的问题
- 使用STL map 时遇到的两个问题
- STL 使用遇到的问题汇总(更新中)
- memcpy函数的使用遇到的问题
- STL中的find()函数,kmp的替代品
- STL之rb_tree的find函数
- 使用scanf函数遇到的问题
- STL map<char*,void*> 的find问题
- STL中vector,find,insert的使用
- STL模板特化遇到的问题
- STL分离编译遇到的问题
- c++STL中遇到的问题
- stl map find使用不当导致的低概率core dump问题的定位
- 【STL】find的用法
- C++的find函数使用
- npm使用过程中遇到的 Cannot find module 'internal/fs' 的问题
- Fragment使用带参数的构造函数遇到的问题
- 【引用】iphone开发常用代码(不断更新)
- Sencha Touch 2.0 组件:Carousels、List、TabPanel 之用法简介
- Linux防火墙应用珠玑
- 几个数学函数
- 智能卡的操作系统——COS
- 使用STL的find函数遇到的问题
- 股票先购权
- DOM与JavaScript、jQuery之间的关系
- Nokia N9 安装vlc,mplayer
- Android Message 及其使用
- C++ Template and Inheritance
- 推荐11本对程序员最有影响力的书籍
- 在CentOS下安装php的json扩展
- python调用系统命令的方法