map本质:
本质上就是数组,关联数组,map就是键到值得一个映射,并且重载了[]符号,所以可以像数组一样用。
map<string,int> cnt;
//前键后值,键就可以理解为索引
map用法总结
1 头文件
#include <map>
2 定义
map<string, int> my_Map;
或者是typedef map<string, int> MY_MAP;
MY_MAP my_Map;
3 插入数据
(1) my_Map["a"] = 1;
(2) my_Map.insert(map<string, int>::value_type("b",2));
(3) my_Map.insert(pair<string,int>("c",3));
(4) my_Map.insert(make_pair<string,int>("d",4));