#include <iostream>
#include <cstdio>
#include <map> using namespace std; int main()
{
// map && multimap
// 键值映射容器,一对一,一对多
// 都是红黑变体的平衡二叉树结构 map<int,string> map1; // 插入元素 // insert插入
map1.insert(pair<int,string>(,"ACM"));
map1.insert(make_pair(,"ACMER"));
map1.insert(map<int,string>::value_type(,"WIN")); // 重载运算符赋值
map1[]="I WIN";
// 没有元素时,插入元素,有元素时,重新赋值
// 比较方便的用法 // 遍历也很方便,如果知道值的话
for(int i=;i<=;++i)
{
cout<<map1[i]<<endl;
} cout<<endl;
// 当然,这才是正规的遍历方式
for(map<int,string>::iterator it=map1.begin();it!=map1.end();++it)
{
cout<<(*it).first<<' '<<(*it).second<<endl;
}
cout<<endl; map<int,string>::iterator it=map1.find(); map1.erase(it); for(map<int,string>::iterator it=map1.begin();it!=map1.end();++it)
{
cout<<(*it).first<<' '<<(*it).second<<endl;
}
cout<<endl; map1[]="haha"; map1[]="heihei"; for(map<int,string>::iterator it=map1.begin();it!=map1.end();++it)
{
cout<<(*it).first<<' '<<(*it).second<<endl;
}
cout<<endl; // 查找小于等于3的键
it=map1.equal_range().first; map1.erase(it);
for(map<int,string>::iterator it=map1.begin();it!=map1.end();++it)
{
cout<<(*it).first<<' '<<(*it).second<<endl;
}
cout<<endl; // 查找大于1的键
it=map1.equal_range().second;
map1.erase(it);
for(map<int,string>::iterator it=map1.begin();it!=map1.end();++it)
{
cout<<(*it).first<<' '<<(*it).second<<endl;
}
cout<<endl; // multimap 与 map类似
// count,可以用来计算键有多少个值与之对应 return ;
}

STL-map/multimap 简述的更多相关文章

  1. 2.9 C++STL map/multimap容器详解

    文章目录 2.9.1 引入 2.9.2 代码示例 map案列 multimap案列 2.9.3 代码运行结果 总结 2.9.1 引入 map相对于set区别,map具有键值和实值,所有元素根据键值自动 ...

  2. STL::map/multimap

    map: 默认根据 key 排序(从小到大),能够通过 backet operator(operator [ ]) 来获取元素,内部由二叉搜索树来实现(binary search trees). mu ...

  3. STL——容器(Map & multimap)的简述与构造

    1. map/multimap 的简介 map 是标准的关联式容器,一个 map 里存储的元素是一个键值对序列,叫做 (key,value) 键值对.它提供基于 key 快速检索数据的能力. map ...

  4. STL Map和multimap 容器

    STL Map和multimap 容器 map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供 基于key的快速检索能力.       ...

  5. STL中的map/multimap小结

    (1)使用map/multimap之前必须包含头文件<map>:#include<map> 并且和所有的关联式容器一样,map/multimap通常以平衡二叉树来完成 (2)n ...

  6. STL:map/multimap用法详解

    map/multimap 使用map/multimap之前要加入头文件#include<map>,map和multimap将key/value当作元素,进行管理.它们可根据key的排序准则 ...

  7. iBinary C++STL模板库关联容器之map/multimap

    目录 一丶关联容器map/multimap 容器 二丶代码例子 1.map的三种插入数据的方法 3.map集合的遍历 4.验证map集合数据是否插入成功 5.map数据的查找 6.Map集合删除元素以 ...

  8. STL之六:map/multimap用法详解

    转载于:http://blog.csdn.net/longshengguoji/article/details/8547007 map/multimap 使用map/multimap之前要加入头文件# ...

  9. STL之map&multimap使用简介

    map 1.insert 第一种:用insert函数插入pair数据 #include <map> #include <string> #include <iostrea ...

  10. STL——容器(Map & multimap)的删除

    Map & multimap 的删除 map.clear();           //删除所有元素 map.erase(pos);      //删除pos迭代器所指的元素,返回下一个元素的 ...

随机推荐

  1. 脚本、脚本语言、shell脚本

    脚本是批处理文件的延伸,是一种纯文本保存的程序,一般来说的计算机脚本程序是确定的一系列控制计算机进行运算操作动作的组合,在其中可以实现一定的逻辑分支等.脚本程序相对一般程序开发来说比较接近自然语言,可 ...

  2. 深入分析Java反射(三)-泛型

    前提 Java反射的API在JavaSE1.7的时候已经基本完善,但是本文编写的时候使用的是Oracle JDK11,因为JDK11对于sun包下的源码也上传了,可以直接通过IDE查看对应的源码和进行 ...

  3. Redis Cluster 介绍与搭建

    转:http://blog.csdn.net/men_wen/article/details/72853078 Redis Cluster 介绍与搭建 1. Redis Cluster介绍 Redis ...

  4. 《Head first设计模式》之单例模式

    单例模式(书中叫单件模式,个人习惯叫单例)确保一个类只有一个实例,并提供一个全局访问点. 有一些对象我们只需要一个,比方说:线程池.缓存.对话框.处理器偏好设置和注册表的对象等等.事实上,这类对象只能 ...

  5. 基于python的密码字典生成器

    最近在网上看到一些作品,然后对其进行了一些完善.只是用于学习,不要去干坏事哦.程序来源于网络,我只是做了一些优化. #!/usr/bin/python# -*- coding:utf-8 -*-# @ ...

  6. lwip nd没有实现ra,contik有参考

    lwip中关于nd的实现,没有路由器的功能,不能发送ra 在contiki中发现有nd发送ra的实现, contiki/core/net/ipv6/uip-ds6.c 在rs的接收处理中,发送soll ...

  7. python3 kubernetes api 使用

    一.安装 github:https://github.com/kubernetes-client/python 安装 pip install kubernetes 二.认证 1.kubeconfig文 ...

  8. 珠峰-buffer-流事件

    #### Buffer // 字符串的二进制转10进制 let r = parseInt('11111111', 2); console.log(r); // 打印 255 // Number类型转为 ...

  9. 实验一 GIT 代码版本管理

    实验一  GIT 代码版本管理 实验目的: 1)了解分布式分布式版本控制系统的核心机理: 2)   熟练掌握git的基本指令和分支管理指令: 实验内容: 1)安装git 2)初始配置git ,git ...

  10. scrapy的useragent与代理ip

    scrapy中的useragent与代理ip 方法一: user-agent我们可以直接在settings.py中更改,如下图,这样修改比较简单,但是并不推荐,更推荐的方法是修改使用scrapy的中间 ...