c++ - STL Map 在搜索尝试时抛出错误

标签 c++ string stl maps

我正在尝试创建一个充满字符串作为键和整数作为值的映射。当我尝试使用它进行搜索时,问题就开始了。有人可以告诉我哪里出错了吗?是我在同一条语句中有两个Map吗?

    invale is "ale"
    roomno = 2;
    // roomlist is a map
    // rinventory is another map

    if( roomlist[roomno].rinventory.find( invale ) != map<string, int>::end());

我得到的错误如下。什么重载函数?这确实是一个冗长的错误。

error C2668: 'std::_Tree<_Traits>::end' : ambiguous call to overloaded function
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\xtree(569): could be 'std::_Tree<_Traits>::const_iterator std::_Tree<_Traits>::end(void) const'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\xtree(564): or       'std::_Tree<_Traits>::iterator std::_Tree<_Traits>::end(void)'
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1>        ]
1>        while trying to match the argument list '(void)'    

提前谢谢你。

最佳答案

尝试将其更改为:

if( roomlist[roomno].rinventory.find( invale ) != roomlist[roomno].rinventory.end());

关于c++ - STL Map 在搜索尝试时抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8543609/

相关文章:

c++ - STL map 在删除第一对后不会添加一对

c++ - C++ 中的正则表达式 : Requires compiler support error

c++ - (clang/llvm-mc/lld) Hello World (x86-64 windows & linux)

c++ - "Where"这个重载运算符是否接受 "out"?

javascript - 在 Javascript 中将复杂的字符串表达式解析为 bool 值

c++11 enable_if 错误 - 模板参数重新声明

c++ - 有没有办法为每次使用 make 命令时运行程序的 c++ 生成文件?

c - 在 c 中用另一个字符串替换一部分字符串的最佳方法?

cucumber 场景大纲 : Passing empty string "" as value in Examples table

c++ - 为什么STL比较函数不是成员?