我在使用find()函数时出错。下面是代码:find()问题
#include <iostream>
#include <map>
#define N 100000
using namespace std;
int main (int argc, char * const argv[]) {
map<int,int> m;
for (int i=0; i<N; i++) m[i]=i;
find(m.begin(), m.end(), 5);
return 0;
}
我发现了一个compiller错误:
error: no match for 'operator==' in '__first. __gnu_debug::_Safe_iterator<_Iterator, _Sequence>::operator* [with _Iterator = std::_Rb_tree_iterator<std::pair<const int, int> >, _Sequence = __gnu_debug_def::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >]() == __val'
包括 '算法' 没什么变化。在VS2008中编译显示类似的错误。
我知道m.find(),但我真的也需要使用find()了。
非常感谢您的协助!
P.S.实际上,任务是比较m.find(5)和find(m.begin(),m.end(),5)的速度,所以我需要使它们都正常工作。
与比较简单的容器比较,这不是一个更好的测试吗? – 2009-07-17 22:04:11
你能说_why_你需要std :: find而不是成员函数吗?成员函数要快得多。 – rlbond 2009-07-17 22:32:02