作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能很简单,但我醒得太久了。
所以我有一个 map
iter=mapInKey.find(int)->second;
if (iter != mapInKey.end() )
{
outFileTxt << iter;
}
但我得到这个错误:no matching function for call to std::map<int, std::basic_string<char> >::find(std::string&)
我只想输出另一对int值
最佳答案
像这样
std::map <int,std::string>::iterator it = mapInKey.find( val ); //val is the integer key you search for
if(it != mapInKey.end()){
// do something
cout<< it->second; // this will print the string
}
编辑
我想你想按字符串搜索。那么你宣布 map 错误。用这个
map<string,int> m;
m["Hi"]= 1;
m["Hello"]= 2;
map<string,int>::iterator it = m.find("Hello");
if(it != m.end())
{
cout<< it->first<<":"<<it->second<<endl;
}
关于c++ - 如何在 int、string 的 map 上使用查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23507859/
我是一名优秀的程序员,十分优秀!