#include<iostream>
#include<cstdio>
#include<map> //按键值大小构成二叉搜索树
using namespace std;
map<int, string> a;
int main()
{
a.insert(map<int, string>::value_type(,"li"));
a.insert(map<int, string>::value_type(,"LI"));//键值存在,插入失败
a.insert(pair<int, string>(, "yang"));
a.insert(pair<int, string>(, "YANG"));//键值存在,插入失败
a[]="wang";
a[]="WANG";//键值存在,进行覆盖
a.insert(make_pair(,"dong"));
a.insert(make_pair(,"DONG"));//键值存在,插入失败
map<int, string>::iterator it;
for(it=a.begin(); it!=a.end(); it++)
{
cout<<it->first<<" "<<it->second<<endl;
} if(a.find()!=a.end())
{
cout<<"find success!"<<endl;
}
else
{
cout<<"losing finding!"<<endl;
} if(a.count()==true)
{
cout<<"find success!"<<endl;
}
else
{
cout<<"losing find! "<<endl;
}
cout<<"map中元素个数为"<<a.size()<<endl;
a.erase(a.begin(),a.end());
if(a.empty())
{
cout<<"map is empty"<<endl;
}
else
{
cout<<"map is not empty"<<endl;
}
return ;
}

C++STL库中map容器常用应用的更多相关文章

  1. C++STL库中vector容器常用应用

    #include<iostream> #include<vector> #include<algorithm> using namespace std; int m ...

  2. C++STL 库中set容器应用

    #include<iostream> #include<cstdio> #include<set> using namespace std; set<int& ...

  3. C++ STL 中 map 容器

    C++ STL 中 map 容器 Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据 处理能力,由于这个特性,它 ...

  4. STL库中string类内存布局的探究

    在STL中有着一个类就是string类,他的内存布局和存储机制究竟是怎么样的呢? 这就是建立好的string 可以看出,图中用黄色框框标注的部分就是主要区域 我们用来给string对象进行初始化的字符 ...

  5. 【转】C++中map容器的说明和使用技巧

    C++中map容器提供一个键值对容器,map与multimap差别仅仅在于multiple允许一个键对应多个值. 一.map的说明    1   头文件   #include   <map> ...

  6. C++中map容器的说明和使用技巧

    C++中map容器提供一个键值对容器,map与multimap差别仅仅在于multiple允许一个键对应多个值. 一.map的说明 1 头文件 #include <map> 2 定义 ma ...

  7. STL标准库中的容器

    容器:顾名思义,我的理解就是把同一种数据类型括起来,作为一捆.如vector<int> ,vector就是个容器,里面全是一个个的int型数据. 容器包括三大块: 顺序型容器: (1)ve ...

  8. 《深入实践C++模板编程》之六——标准库中的容器

    1.容器的基本要求 a.并非所有的数据都可以放进容器当中.各种容器模板对所存数据类型都有一个基本要求——可复制构造.将数据放进容器的过程就是通过数据的复制构造函数在容器内创建数据的一个副本的过程. b ...

  9. c++之旅:模板库中的容器

    容器 C++中的容器包括array, vector, list,map,set 数组 array不可变长,创建时其大小就固定了,array中可以存储各种数据类型包括对象,不过array是在栈上分配的, ...

随机推荐

  1. term frequency–inverse document frequency

    term frequency–inverse document frequency

  2. linux c编程:进程环境

    一 进程终止: ⼀个进程可以登记若⼲个(具体⾃⼰验证⼀下)个函数,这些函数由exit⾃动调⽤,这些函数被称为终⽌处理函数, atexit函数可以登记这些函数. exit调⽤终⽌处理函数的顺序和atex ...

  3. ALV 表头 ADD_TEXT

    [转自http://lz357502668.blog.163.com/blog/static/16496743201252891452493/] CALL METHOD valid_reference ...

  4. Intel Quick Sync Video Encoder

    本篇记录Intel E3 1275处理器集成显卡的硬编码预研过程. 步骤如下: (1)环境搭建 (2)demo编译,测试 (3)研究demo源码,Media SDK API使用 (4)编写so动态库封 ...

  5. Ubuntu中安装jdk环境

    1.Installing default JRE/JDK sudo apt-get update sudo apt-get install default-jre sudo apt-get insta ...

  6. 每天一个Linux命令(36)ps命令

          Linux中的ps命令是Process Status的缩写.       ps命令用于报告当前系统的进程状态.可以搭配kill指令随时中断.删除不必要的程序.       (1)用法:   ...

  7. vRA7.x services do not register after a restart (2147446)

    After restarting the vRealize Automation Appliance, you experience these symptoms: In the vRealize A ...

  8. [算法]去掉字符串中连续出现的k个0子串

    题目: 给定一个字符串str和一个整数k,如果str中正好有k个‘0’字符出现时,把k个连续的‘0’字符去除,返回处理后的字符串. 举例: str=”A00B”,k=2,返回“AB” str=”A00 ...

  9. JSON与AJAX的使用

    主要内容: 一.JSON数据 二.JSON字符串与Java对象的相互转换 三.JSON字符串与JavaScript对象的相互转换 四.AJAX异步加载 一.JSON数据 1.JSON语法规则: 2.J ...

  10. curl使用手册

    查询curl耗时 curl -o /dev/null -s -w %{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_ ...