在地图上使用find< pair,int> [英] Using find on map<pair, int>
问题描述
如果您的地图定义为
<$ c $如何使用 const_iterator
c> typedef std :: pair< int,int> MyPair;
map< MyPair,int> MyData;
,其中对
b
$ b
如果只是 map< int,int>
,我知道如何使用 const_iterator
like
typedef map< int,int> MyMap;
MyMap :: const_iterator it =
MyMap.find(0); $
如果你不使用C ++ 11 ,最方便的还是为地图类型做一个 typedef
:
typedef std :: map< MyPair,int> map_type;
然后
map_type :: const_iterator it = MyMap.find(make_pair(0,0));
(我也更改了传递给的参数
, int
与您的地图不兼容。)
如果您使用C ++ 11 ,你也可以做
auto it = MyMap.find(make_pair );
How do you use find with a const_iterator
if you have a map defined as
typedef std::pair<int, int> MyPair;
map<MyPair, int> MyMap;
with the pair
defined as the key.
If it was just map<int, int>
, I know how to use a const_iterator
like
typedef map<int, int> MyMap;
MyMap::const_iterator it =
MyMap.find(0);
etc..
If you are not using C++11, the most convenient is to also do a typedef
for the map type:
typedef std::map<MyPair, int> map_type;
And then
map_type::const_iterator it = MyMap.find(make_pair(0, 0));
(I also changed the parameter passed to find
, as a bare int
is not compatible with your map).
If you are using C++11, you can also do simply
auto it = MyMap.find(make_pair(0, 0));
这篇关于在地图上使用find< pair,int>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!