如何在int,string类型的映射上使用find
how to use find on a map of int,string
这可能很容易,但我已经醒了太久了。
我有一个map<Int,>和我试图使用函数find
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<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;
}
相关文章:
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 将函数类成员映射到类本身内部
- 如何在 C# 中映射双 C 结构指针?
- 如何在C++中使用结构生成映射
- 使用std::函数映射对象方法
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- C++映射分割错误(核心转储)
- 内联映射初始化的动态atexit析构函数崩溃
- 使用"std::unordereded_map"映射到"std::list"对象
- 如何从多映射中删除特定的重复项
- 为什么映射插入和 map.find() 的单次迭代比插入和 map.find() 的两次单独迭代慢得多
- 为什么要对 map::find 应用不存在的键将返回一个C++中第一个值映射大小的迭代器
- 在无序映射<字符串上使用 find(),向量<string>>与 C++ 中的有序映射花费相同的时间
- 多映射less_equal导致错误的 find() 结果
- 使用结构作为映射的键和值.find() 操作给出错误
- C++stl::使用结构映射find
- 如何在int,string类型的映射上使用find
- 用于成员函数映射的c++find()