C++ std::map用法简介
来源:互联网 发布:汉王扫描仪软件 编辑:程序博客网 时间:2024/06/01 07:51
#include "map" //引入头文件
初始化:
std::map <int, std::string> _map1; //初始化//c++11中引入的,可以直接在初始化时赋值std::map <int, std::string> _map = {{0,"11"},{2,"22"},{3,"33"},};
插入:
// 如果已经存在键值200,则会作赋值修改操作,如果没有则插入_map[200] = "booomm";//通过insert插入_map.insert(std::pair<int, std::string>(4, "33333"));
取值:
//Map中元素取值主要有at和[]两种操作,at会作下标检查,而[]不会。std::cout<< _map.at(100).c_str()<< std::endl;//使用at会进行关键字检查,因此下面语句会报错std::cout << _map.at(4).c_str() << std::endl;//不会报错std::cout << _map[300].c_str() << std::endl;//ID_Name中没有关键字200,使用[]取值会导致插入,因此不会报错,但打印结果为空
参考资料:http://blog.csdn.net/shuzfan/article/details/53115922
阅读全文
0 0
- C++ std::map用法简介
- std::map用法
- std map用法详解
- std::map的用法
- std::map用法
- std::map用法
- std::map用法
- std:map用法
- std::map用法
- std::map用法
- std::map用法
- std::map用法
- std::map用法
- std 学习 std::map用法学习
- std::map的用法总结
- std::map的用法总结
- std::map的用法总结
- std::map的一些用法
- 严蔚敏迪杰斯特拉算法改进
- Android SDK 与API版本对应关系
- 级数求和
- 常用numpy函数
- cocos2d-x 之 简单数据存储——Userdefault
- C++ std::map用法简介
- Comprehensive learning path – Data Science in Python
- 算法练习(18):Jump Game
- 基于Spring开发——自定义标签及其解析
- tomcat 上传超出限制的大文件的时候,无响应,服务器端有限制大小
- C_笔记整理_2
- Unity简单的单例实例
- 带父标签的自定义标签
- <最短路模板> 热浪