// unordered_map::find
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
int main ()
{
std::unordered_map<std::string,double> mymap;
mymap["mom"] = 5.4;
mymap["dad"] = 6.1;
mymap["bro"] = 5.9;
std::string input;
std::cout << "who? ";
getline (std::cin,input);
std::unordered_map<std::string,double>::const_iterator got = mymap.find (input);
**cout << mymap.find(input) <<endl;
cout << got <<endl;
cout << mymap.end() <<endl;**
if ( got == mymap.end() )
std::cout << "not found";
else
std::cout << got->first << " is " << got->second;
std::cout << std::endl;
return 0;
}
イテレータが取得したものを印刷しようとすると、mymap.find と mymap.end にもエラーが発生するのはなぜですか。
エラー:
エラー 1 エラー C2679: バイナリ '<<' : 型 'std::_List_iterator<_Mylist>' の右側のオペランドを取る演算子が見つかりません (または、受け入れ可能な変換がありません) c:\users\chunhaun\c++レッスン\自己学習\自己学習\associative_container.cpp 19
6 IntelliSense: これらのオペランドに一致する演算子 "<<" はありません c:\users\chunhaun\c++lessons\self-learning\self-learning\associative_container.cpp 21