- 创建字典
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
map<string, int> mymap;
}
- 赋值
2.1 指定元素赋值
mymap["abc"] = 1;
2.2 添加键值对
mymap.insert(make_pair("bcd", 2));
- 字典的顺序输出
3.1 map<string, int>::iterator it = mymap.begin()
for(map<string, int>::iterator it = mymap.begin(); it != mymap.end(); it++){
if(it -> second > 1){
cout << it -> first << " " << it->second << endl;
}
}
3.2 auto it = mymap.begin()
for(auto it = mymap.begin(); it != mymap.end(); it++){
if(it -> second > 1){
cout << it -> first << " " << it->second << endl;
}
}