#include<iostream>
#include<map>
using namespace std;
int main(){
map<string,int> m;
m["a"]=3;
m["b"]=56;
map<string,int>::iterator it; //iterator即迭代器,it指代map中元素
for(it=m.begin();it!=m.end();it++){
cout << it->first << " " << it->second << " " << endl; //此中it->first指代键,it->second指代值
}
it=m.begin();
string s=it->first;
int i=it->second;
cout << s << " " << i << endl;
i=m["b"];
cout << i;
return 0;
}
STL之map定义,使用与遍历
最新推荐文章于 2024-07-19 16:24:54 发布