STL之map&multimap使用简介
map
1.insert
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main()
{
map<int, string> map;
map.insert(pair<int, string>(, “one”));
map.insert(pair<int, string>(, “two”));
map.insert(pair<int, string>(, “three”));
map<int, string>::iterator iter;
for(iter = map.begin(); iter != map.end(); iter++)
{
cout<<iter->first<<” ”<<iter->second<<end;
}
}
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main()
{
map<int, string> map;
map.insert(map<int, string>::value_type (, “one”));
map.insert(map<int, string>::value_type (, “two”));
map.insert(map<int, string>::value_type (, “three”));
map<int, string>::iterator iter;
for(iter = map.begin(); iter != map.end(); iter++)
{
cout<<iter->first<<” ”<<iter->second<<end;
}
}
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main()
{
map<int, string> map;
map[]=“one”;
map[]=“two”;
map[]= “three”;
map<int, string>::iterator iter;
for(iter = map.begin(); iter != map.end(); iter++)
{
cout<<iter->first<<” ”<<iter->second<<end;
}
}
map 总是以(key,value)的形式存在,当插入的数据的key已经存在时,会形成覆盖,map内部使用红黑树实现。
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main()
{
map<int, string> map;
map.insert(pair<int, string>(, “one”));
map.insert(pair<int, string>(, “two”));
map.insert(pair<int, string>(, “three”));
for(int index=;index<=map.size();index++)
{
cout<<map[index]<<endl;
}
}
4.查找
map.find()如果查找到,返回指向结果的迭代器,如果没有找到到,返回map.end()
5.上下界
6.清空与判空
STL之map&multimap使用简介的更多相关文章
- STL:map/multimap用法详解
map/multimap 使用map/multimap之前要加入头文件#include<map>,map和multimap将key/value当作元素,进行管理.它们可根据key的排序准则 ...
- 【STL】-Map/Multimap的用法
初始化: map<string,double> salaries; 算法: 1. 赋值.salaries[ "Pat" ] = 75000.00; 2. 无效的索引将自 ...
- STL——容器(Map & multimap)的简述与构造
1. map/multimap 的简介 map 是标准的关联式容器,一个 map 里存储的元素是一个键值对序列,叫做 (key,value) 键值对.它提供基于 key 快速检索数据的能力. map ...
- 09--STL关联容器(map/multimap)
一:map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. map中key值是唯一的.集合中的元素按一定的顺 ...
- 【C++ STL】Map和Multimap
1.结构 Map和multimap将key/value pair(键值/实值 队组)当作元素,进行管理.他们根据key的排序准则将元素排序.multimap允许重复元素,map不允许. 元素要求: k ...
- STL中的map/multimap小结
(1)使用map/multimap之前必须包含头文件<map>:#include<map> 并且和所有的关联式容器一样,map/multimap通常以平衡二叉树来完成 (2)n ...
- iBinary C++STL模板库关联容器之map/multimap
目录 一丶关联容器map/multimap 容器 二丶代码例子 1.map的三种插入数据的方法 3.map集合的遍历 4.验证map集合数据是否插入成功 5.map数据的查找 6.Map集合删除元素以 ...
- STL之Map和multimap容器
1.Map和multimap容器 1)map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. 2)map中key值是唯一的.集合中的元素按一 ...
- STL中 map 和 multimap
1. 所在头文件<map>. 命名空间std, 声明如下: namespace std{ template <class Key,class T, class Compare = l ...
随机推荐
- PASCAL VOC数据集分析
http://blog.csdn.net/zhangjunbob/article/details/52769381
- python-类对象以列表切片模式操作
#类对象以列表切片模式操作 class Person: def __init__(self): self.cache=[] def __setitem__(self, key, value): #修改 ...
- cudpp库使用说明
所有信息是我个人在使用过程中的小小经验,不是什么权威性文档,旨在帮助需要研究此类信息的朋友少走点弯路. 整个项目的主函数,一切从这里开始 在cudpp_testrig右键属性页里找到调试,在命令行里输 ...
- C++编程经验总结1
面向对象的精髓: 主函数其实就是对于类的元素和动作的重新组合来进行一项活动. 一个思想概念:程设是清楚的,完美的. 数学是清楚的,是完美的. 物理是有趣的,尤其是量子物理 生物是清楚的,尤其是基因 外 ...
- JS浏览器的三种弹框:
1.alert:使用alert弹框提示信息,最后都会被转化为字符串输出(因为调用了toString这个方法).比如alert(1+1)弹出的结果应该是字符串形式的“2”. 2.Confirm:在ale ...
- Problem 1004-2017 ACM/ICPC Asia Regional Shenyang Online
题目来源:array array array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- C#+Winform开发窗体程序
学习笔记 第一章:winform基础 一.概述 1.Windows Form(简称WinForm) 是微软.NET平台下用于开发"图形界面"应用程序的组件. 2.C/S架构 客户机 ...
- gd库 给底图写入文字问题
png-8的图片 设置颜色会返回false,换成png-24的就可以了
- mysql数据库设置外键,更新与删除选项
CASCADE:父表delete.update的时候,子表会delete.update掉关联记录:SET NULL:父表delete.update的时候,子表会将关联记录的外键字段所在列设为null, ...
- mysql基础 反范式化