28 map
来源:互联网 发布:西游之路坐骑进阶数据 编辑:程序博客网 时间:2024/06/06 02:14
标准库的map类型
使用map得包含map类所在的头文件
include < map >
定义一个map对象:
map
#include <map>#include <string>#include <iostream>using namespace std;int main(){ //插入到map容器内部的元素默认是按照key从小到大来排序。 //key类型一定要重载<运算符 map <string, int> mapTest; mapTest["aaa"] = 100; mapTest["eee"] = 500; mapTest.insert(map<string, int>::value_type("bbb", 200)); mapTest.insert(pair<string,int>("ccc",300)); mapTest.insert(make_pair("ddd",400)); map<string, int>::iterator it;//const_iterator,则下面3000不能修改 it = mapTest.find("ccc"); if (it != mapTest.end()) { it->second = 3000; } mapTest.erase("bbb"); //map<string, int>::const_iterator it; it = mapTest.find("ccc"); if (it != mapTest.end()) { mapTest.erase(it); } //map<string, int>::const_iterator it; for (it = mapTest.begin(); it != mapTest.end(); ++it) { cout << it->first << " " << it->second << endl; } return 0;}
输出:
aaa 100
ddd 400
eee 500
0 0
- 28 map
- c++ 28 map
- map
- MAP
- map
- MAP
- map
- map
- map
- Map
- Map
- Map
- map
- map
- Map
- .map
- map
- MAP
- Maven配置
- C++实验2-项目1标准体重
- 项目14-三角形类雏形(3)
- 数组指针和指针数组
- 送伞
- 28 map
- ## BaseAdapter的优化 ##
- a1005. Spell It Right (20)
- 【HDOJ 5653】 Bomber Man wants to bomb an Array.(DP)
- HDOJ 5651-xiaoxin juju needs help【字符的全排列】
- 红黑树代码实践
- 归园田居 东晋 陶渊明 注音版
- AOJ2249Contest Page(最短路径spfa)
- 借助SystemBarTint实现透明标题栏(沉浸式)