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)の速度を比較することで、両者を適切に動作させる必要があります。
ベクターなどのよりシンプルなコンテナと比較するとよいでしょうか? –
メンバー関数の代わりにstd :: findが必要な_why_と言うことができますか?メンバ関数ははるかに高速です。 – rlbond