28 map
2016-03-28 20:22
281 查看
标准库的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
相关文章推荐
- android Google Map获取地理位置信息的方法
- Spark RDD API详解(一) Map和Reduce
- Python中map()函数浅析
- Android使用Google Map浅谈
- Erlang中的映射组Map详细介绍
- c++中map的基本用法和嵌套用法实例分析
- 百度地图给map添加右键菜单(判断是否为marker)
- JavaScript中实现Map的示例代码
- jquery中map函数与each函数的区别实例介绍
- jquery中map函数遍历数组用法实例
- jquery与google map api结合使用 控件,监听器
- jquery遍历数组与筛选数组的方法
- JavaScript中实现map功能代码分享
- 用json方式实现在 js 中建立一个map
- Android Map新用法:MapFragment应用介绍
- js Map List 遍历使用示例
- java实现遍历Map的方法
- velocity显示List与Map的方法详细解析
- Google Map Api和GOOGLE Search Api整合实现代码
- 关于STL中的map容器的一些总结