如何在地图中搜索一对本身的键
How to search for a key which is a pair itself, in a map?
我想检查映射中是否存在密钥(本身就是一对(。
我是使用map的新手,找不到一个可以检查键(一对(的功能。
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
typedef pair<ll,ll> my_key_type;
typedef map<my_key_type,ll> my_map_type;
int main()
{
my_map_type ma;
my_map_type::iterator it;
ma.insert(make_pair(my_key_type(30,40),6));
it=ma.find(30,40);
if(it==ma.end())
{
cout<<"not present";
return 0;
}
cout<<"present";
return 0;
}
我收到以下错误-
no matching function for call to ‘std::map<std::pair<long long int, long long int>, long long int>::find(int, int)’ it=ma.find(30,40);
当您使用
it=ma.find(30,40);
编译器不会自动将参数转换为对。您必须明确执行此操作。
it=ma.find(std::make_pair(30,40));
或更简单的版本
it=ma.find({30,40});
相关文章:
- 为什么我在地图中搜索STL时差很大?
- C++以迭代方式搜索混合类型地图
- 我们可以使用地图而不是二叉搜索吗?
- 有序地图字符串搜索与整数搜索之间的时间复杂度
- 在地图中搜索结构元素
- unordered_maps的向量,在地图中搜索太慢
- 如何在地图中搜索一对本身的键
- 如何从特定位置开始搜索地图/多映像
- 我想使用列表中的项目在地图中搜索
- 如何在C 中搜索地图
- 在地图中按矢量搜索键
- 在地图中搜索值时'operator='不匹配
- C - 搜索地图中具有相同值的所有键的最快方法是什么
- 按值搜索地图
- 在插入之前使用 lower_bound 搜索地图的好处.相当于ptr_map?
- 为什么向量和地图搜索比静态比较要慢得多
- 如何使用其中一个键搜索具有多个键的地图
- 可以同时搜索相同成本的值和关键字的地图?象征主义地图
- 使用地图库构建电话目录搜索向量
- 使用多关键字地图进行有效搜索