#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. 题解【RQNOJ PID497 0/1字串问题】

    \[ \texttt{Description} \] 编程找出符合下列条件的字符串:①字符串中仅包含 0 和 1 两个字符:②字符串的长度为 n :③字符串中不包含连续重复三次的子串. \[ \tex ...

  2. gridFS-Nginx的安装与使用

    在使用gridFs的nginx模块时,先确认好你的机器上已经安装好了mongo 首先通过git将最新的gridfs的nginx模块下载到本地 git clone https://github.com/ ...

  3. pytorch之 CNN

    # library # standard library import os # third-party library import torch import torch.nn as nn impo ...

  4. pycharm template 设置

    ${PROJECT_NAME} - 当前Project名称; (the name of the current project. ) ${NAME} -创建文件的对话框中制定的文件名; (the na ...

  5. webpack 中那些最易混淆的 5 个知识点

    学习博客:https://blog.csdn.net/wsyzxxn9/article/details/90677770 学习lodash:https://www.html.cn/doc/lodash ...

  6. webpack构建vue单文件组件

    1.安装vue-loader和vue-template-compiler npm i vue-loader vue-template-compiler --save-dev 2.配置webpack.c ...

  7. [PHP] 使用PHP在mongodb中进行count查询

    在php7的mongodb扩展中,当要查询某个集合在某个条件下的数据个数时,可以使用下面的方式来获取. 比原生的命令要复杂许多 比旧版mongo扩展也复杂许多 需要使用到MongoDB\Driver\ ...

  8. CSS中元素的显示模式

     在CSS中,根据元素显示模式的不同元素标签被分为了两类:行内元素(inline-level).块级元素(block-level). 1,首先介绍什么是行内元素,什么又是块级元素? 1.1,行内元素就 ...

  9. 同一台电脑安装python2&python3

    [安装之前,先了解一下概念] python是什么? Python是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum于1989年发明,第一个公开发行版发行于1991年. ...

  10. everspin最新1Gb容量扩大MRAM吸引力

    everspin提供了8/16-bit的DDR4-1333MT/s(667MHz)接口,但与较旧的基于DDR3的MRAM组件一样,时序上的差异使得其难以成为DRAM(动态随机存取器)的直接替代品.   ...