在地图上使用find <pair,int>

4 c++ dictionary

const_iterator如果您将地图定义为,如何使用find

pair

map<int, int>

const_iterator定义为键.

如果它只是const_iterator,我知道如何使用pair喜欢

map<int, int>

const_iterator

等等..

Jon*_*Jon 6

如果您不使用C++ 11,最方便的是也typedef为地图类型执行:

typedef std::map<MyPair, int> map_type;
Run Code Online (Sandbox Code Playgroud)

然后

map_type::const_iterator it = MyMap.find(make_pair(0, 0));
Run Code Online (Sandbox Code Playgroud)

(我也改变了传递给的参数find,因为裸int与你的地图不兼容).

如果您使用的是C++ 11,那么您也可以做到

auto it = MyMap.find(make_pair(0, 0));
Run Code Online (Sandbox Code Playgroud)