C++ STL 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::iterator it; 定义一个迭代指针it。
it->first 为索引键值,it->second 为值。

此程序在gentoo Linux 下测试没有问题。

/usr/themes/NexTSun/static/images/yovisun-weixin-share.jpg
赞 (4) 分享
声明:原创文章,欢迎转载,请以 超链接 的形式注明 作者标题原始出处查看许可协议
标题C++ STL map 遍历 | 作者:YoviSun
地址https://www.yovisun.com/archive/cpp-stl-map.html
相关文章:暂无
添加新评论
选择表情
手机扫描二维码访问