gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:04:32 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com