map相关用法

输出map中的元素

map的定义是这样的:
#include< map >
map< int ,int >base;
前一个int是关键值,又称first,后面一个int是存下的值的类型,又称second。
输出的时候,我们这样输出,类似双端队列一样。
map< int , int >::iterator it;
for(it = base.begin(); it != base.end(); ++it) maxn = max(maxn, it->second);
//这里的it—>second,表示的是和base中的second的值做对比。
这里有一篇博客讲的更详细:(https://ask.csdn.net/questions/647686)

查找map中的元素

map.count(s)如果返回值是1,则说明map中有相应的s值存在,如果返回值为0,则没有。

猜你喜欢

转载自blog.csdn.net/tangzhide123yy/article/details/80394779