【发布时间】:2013-06-06 23:39:01
【问题描述】:
// 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: 二进制 '' 类型的右手操作数(或者有 不可接受 转换)c:\users\chunhaun\c++lessons\self-learning\self-learning\associative_container.cpp 19
6 IntelliSense:没有运算符“
【问题讨论】:
-
@C.Lang:嗨,我确实放了()。如上图。
-
您是否为自己的问题和 cmets 投票?
-
@ViteFalcon:你不能为自己的东西投票。我赞成评论,因为他正确地编辑了代码。
-
@C.Lang:我只会赞成 cmets 或为讨论增加价值的答案。在这里,他确实对其进行了编辑,但我不明白为什么要赞成修复他的帖子中的错误。无论如何,这是个人喜好:)
标签: c++ hashmap hashtable associative-array unordered-map