stl map容器 学习

时间:2023-03-09 10:06:45
stl map容器 学习

#include<map>

1.map的声明:

map<string,int>map_1;

  map_1 就是一个string对int的映射。

2.map的用法(映射):

map_1["one"]=;//建立映射:one->1
cout<<map_1["one"]<<endl;//重载了[],输出结果为:1

3.map的常用指令:

map_1.size() //返回 map_1中的映射对数
map_1.count("two")//判断 映射key中是否存在 “two”这个键值