STL-map/multimap 简述
#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 简述的更多相关文章
- 2.9 C++STL map/multimap容器详解
文章目录 2.9.1 引入 2.9.2 代码示例 map案列 multimap案列 2.9.3 代码运行结果 总结 2.9.1 引入 map相对于set区别,map具有键值和实值,所有元素根据键值自动 ...
- STL::map/multimap
map: 默认根据 key 排序(从小到大),能够通过 backet operator(operator [ ]) 来获取元素,内部由二叉搜索树来实现(binary search trees). mu ...
- STL——容器(Map & multimap)的简述与构造
1. map/multimap 的简介 map 是标准的关联式容器,一个 map 里存储的元素是一个键值对序列,叫做 (key,value) 键值对.它提供基于 key 快速检索数据的能力. map ...
- STL Map和multimap 容器
STL Map和multimap 容器 map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供 基于key的快速检索能力. ...
- STL中的map/multimap小结
(1)使用map/multimap之前必须包含头文件<map>:#include<map> 并且和所有的关联式容器一样,map/multimap通常以平衡二叉树来完成 (2)n ...
- STL:map/multimap用法详解
map/multimap 使用map/multimap之前要加入头文件#include<map>,map和multimap将key/value当作元素,进行管理.它们可根据key的排序准则 ...
- iBinary C++STL模板库关联容器之map/multimap
目录 一丶关联容器map/multimap 容器 二丶代码例子 1.map的三种插入数据的方法 3.map集合的遍历 4.验证map集合数据是否插入成功 5.map数据的查找 6.Map集合删除元素以 ...
- STL之六:map/multimap用法详解
转载于:http://blog.csdn.net/longshengguoji/article/details/8547007 map/multimap 使用map/multimap之前要加入头文件# ...
- STL之map&multimap使用简介
map 1.insert 第一种:用insert函数插入pair数据 #include <map> #include <string> #include <iostrea ...
- STL——容器(Map & multimap)的删除
Map & multimap 的删除 map.clear(); //删除所有元素 map.erase(pos); //删除pos迭代器所指的元素,返回下一个元素的 ...
随机推荐
- 《windows程序设计》第三章学习心得
第三章是基于对一个windows窗口的学习,来达到对windows程序运行机制的理解. 从语言的角度看消息机制,Windows给程序发消息的本质就是调用"窗口过程"函数. Don' ...
- selenium pyunit单元测试框架
selenium pyunit单元测试框架 #PyUnit框架 #coding = utf - 8 #将要被测试的类 class Widget: def __int__(self,size = (40 ...
- Ubuntu下安装spark
方法一: jps 查看Java 包 sudo apt-get install openjdk** sudo apt-get install scala 选择安装源然后 sudo wget 下载链接 s ...
- Golang设置https访问,以及http如何重定向到https
设置https访问: 原始代码为http监听: func main() { server := &http.Server{ Addr: ":8080", ... } go ...
- 14-SSM整合
今日知识 1. Spring整合MyBatis 2. SSM普通整合 3. SSM整合(Spring和SpringMVC分离) 4. 纯JavaConfig的SSM Spring整合MyBatis 1 ...
- 不重启 清空tomcat日志
1.重定向方法清空文件 [root@localhost logs]# du -h catalina.out 查看文件大小17M catalina.out[root@localhost logs]# ...
- OSPF理论
OSPF简介 OSPF(Open Shortest Path First 开放式最短路径优先)协议是IETF为IP网络开发的IGP路由选择协议.它是一种典型的链路状态(link-state)路由协议. ...
- ssh_key认证
ssh认证流程步骤: 1.主机host_key认证 2.身份验证 3.身份验证通过 原理及更多知识点,请查看好友博客 http://www.cnblogs.com/f-ck-need-u/p/7129 ...
- redis教程-基础数据结构
需要整套redis缓存高可用集群教学视频的加qq:1324981084,本套视频从安装到集群的搭建和源码的解析,从零基础讲解. 一.Redis 有 5 种基础数据结构,分别为:string (字符串) ...
- java设计模式4——原型模式
java设计模式4--原型模式 1.写在前面 本节内容与C++语言的复制构造函数.浅拷贝.深拷贝极为相似,因此建议学习者可以先了解C++的该部分的相关知识,或者学习完本节内容后,也去了解C++的相应内 ...