我创建地图这样的:std::map<int, std::string> mapID;
地图在C++给钥匙,获取字符串
输入:的azazaz [1] =! “串”;
我想用键打印元素是s。 例如
cout << "The string is : " << mapID.at(s)->second << endl;
OR
cout << "The string is : " << mapID.find(s)->second << endl;
但我有错误
error: no matching function for call to ‘std::map >::at(std::string&)’
UPDATE:
while(getline(file,s))
{
cout<< s << endl;
number = atoi(s.c_str());
cout << "The string is: " << mapID.at(number)<< endl;
}
请显示[mcve]。 '1'显然不是一个字符串,所以有些东西是可疑的,但我们需要看到更多的代码来重现问题 – user463035818
如果mapID [1]不存在,它将在1处创建一个元素 – rak007
您列出的代码不能产生给定的错误信息。请向我们展示实际的代码或实际的错误消息。 (最好是我们可以剪切并粘贴到(例如)cpp.sh中的[mcve]) –