我是靠谱客的博主 酷酷航空,这篇文章主要介绍C++ Map的遍历,现在分享给大家,希望可以做个参考。

#include<map>
#include<string>
#include<iostream>
using namespace std;

int main()
{
       map<string,int>   m;
       m["a"]=1;
       m["b"]=2;
       m["c"]=3;
       map<string,int>::iterator it;
       for(it=m.begin();it!=m.end();++it)
              cout<<"key: "<<it->first <<" value: "<<it->second<<endl;
       return     0;
}

 
map<string,int>::iterator it;     定义一个迭代指针it。 
it->first 为索引键值,it->second 为值。

最后

以上就是酷酷航空最近收集整理的关于C++ Map的遍历的全部内容,更多相关C++内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部