C++ 如何使用std::pair生成map.find()函数
我在做map时遇到了这个错误。find(10,20)知道怎么做吗C++ 如何使用std::pair生成map.find()函数,c++,dictionary,std,std-pair,C++,Dictionary,Std,Std Pair,我在做map时遇到了这个错误。find(10,20)知道怎么做吗 Error (active) E0304 no instance of overloaded function "std::map<_Kty, _Ty, _Pr, _Alloc>::find [with _Kty=std::pair<int, int>, _Ty=std::tuple<int, int, int>, _Pr=std::less<std::pair<int, i
Error (active) E0304 no instance of overloaded function "std::map<_Kty,
_Ty, _Pr, _Alloc>::find [with _Kty=std::pair<int, int>, _Ty=std::tuple<int, int, int>, _Pr=std::less<std::pair<int, int>>,
_Alloc=std::allocator<std::pair<const std::pair<int, int>, std::tuple<int, int, int>>>]" matches the argument list Maps
错误(活动)E0304没有重载函数“std::map::find[with _Kty=std::pair,_Ty=std::tuple,_Pr=std::less,
_Alloc=std::allocator]“匹配参数列表映射
#包括
#包括
#包括
int main()
{
std::map myMap;
//在std::map中插入数据
myMap[std::make_-pair(10,20)]=std::make_-tuple(1,2,3);
auto it=myMap.cbegin();
for(auto-const&it:myMap){
std::cout您需要一个std::pair
作为键,而不是两个int
s。当您插入项时,您正确使用了std::make\u pair
。您需要对find
成员函数执行相同的操作,或者,如注释中所述,将您的键包装在大括号中。两者都执行相同的操作;第一个操作更明确,在s中第二种情况是依赖于到std::pair
的隐式转换
auto search = myMap.find(std::make_pair(10, 20));
或
请尝试find({10,20})
。您是否查看了的签名?所有重载都不包含2个参数。myMap.find({10,20});
应该可以工作。
auto search = myMap.find(std::make_pair(10, 20));
auto search = myMap.find({10, 20});