// 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