map_multimap
#include<iostream>
#include<string>
#include<map>
using namespace std; struct SelfType{
int number;
}; void map_find()
{
//map.lower_bound(keyElem);//返回第一个key>=keyElem元素的迭代器
//map.upper_bound(keyElem);//返回第一个key>keyElem元素的迭代器
//map.equal_range(keyElem);//返回一个pair,
//pair.first为第一个key>=keyElem元素的迭代器
//pair.second为第一个key>keyElem元素的迭代器 map<int,string> mapStu;
//1、通过pair的方式插入对象
//mapStu.insert( pair<int,string>(3, "小张"));
//2、通过value_type的方式插入对象
mapStu.insert( map<int, string>::value_type(, "小李") );
//3、通过数组的方式插入值
mapStu[] = "小张";
mapStu[] = "小刘";
mapStu[] = "小赵";
mapStu[] = "小王"; map<int,string>::iterator it_lower,it_upper;
it_lower=mapStu.lower_bound();
it_upper=mapStu.upper_bound();
cout<<it_lower->first<<","<<it_lower->second<<endl;
cout<<it_upper->first<<","<<it_upper->second<<endl;
pair<map<int,string>::iterator,map<int,string>::iterator> mapStuPair=mapStu.equal_range();
it_lower=mapStuPair.first;
it_upper=mapStuPair.second;
cout<<it_lower->first<<","<<it_lower->second<<endl;
if(it_upper !=mapStu.end())
{
cout<<it_upper->first<<","<<it_upper->second<<endl;
}
else
{
cout<<"it_upper ==mapStu.end()"<<endl;
}
/*
3,小刘
4,小赵
5,小王
it_upper ==mapStu.end()
请按任意键继续. . .
*/
} void map_greater()
{
map<int,string,greater<int>> mapStu;
//1、通过pair的方式插入对象
mapStu.insert( pair<int,string>(, "小张"));
//2、通过value_type的方式插入对象
mapStu.insert( map<int, string>::value_type(, "小李") );
//3、通过数组的方式插入值
mapStu[] = "小刘";
mapStu[] = "小王"; map<int,string,greater<int>>::iterator it;
for(it=mapStu.begin();it !=mapStu.end();++it)
{
cout<<it->first<<","<<it->second<<" ";
}
cout<<endl; }
void main()
{
map_find();return;
map_greater();return; map<int, char> mapA;
map<string, float> mapB;
//其中T1,T2还可以用各种指针类型或自定义类型
map<float, char> mapC;
map<int*, float> mapD;
map<SelfType, char> mapE; map<int,string> mapStu;
//1、通过pair的方式插入对象
mapStu.insert( pair<int,string>(, "小张"));
//2、通过value_type的方式插入对象
mapStu.insert( map<int, string>::value_type(, "小李") );
//3、通过数组的方式插入值
mapStu[] = "小刘";
mapStu[] = "小王"; map<int,string>::iterator it;
for(it=mapStu.begin();it !=mapStu.end();++it)
{
cout<<it->first<<","<<it->second<<" ";
}
cout<<endl; string strName = mapStu[];//取操作
cout<<strName.length()<<endl;
//只有当mapStu存在2这个键时才是正确的取操作,否则会自动插入一个实例,键为2,值为初始化值。
for(it=mapStu.begin();it !=mapStu.end();++it)
{
cout<<it->first<<","<<it->second<<" ";
}
cout<<endl; }
#include <iostream>
#include <string>
#include <map>
using namespace std; int main()
{
multimap<string,int> m_map;
string s("中国"),s1("美国");
m_map.insert(make_pair(s,));
m_map.insert(make_pair(s,));
m_map.insert(make_pair(s,));
m_map.insert(make_pair(s1,));
m_map.insert(make_pair(s1,));
m_map.insert(make_pair(s1,));
//方式1
int k;
multimap<string,int>::iterator m;
m = m_map.find(s);
for(k = ;k != m_map.count(s);k++,m++)
cout<<m->first<<"--"<<m->second<<endl;
//方式2
multimap<string,int>::iterator beg,end;
beg = m_map.lower_bound(s1);
end = m_map.upper_bound(s1);
for(m = beg;m != end;m++)
cout<<m->first<<"--"<<m->second<<endl;
//方式3
beg = m_map.equal_range(s).first;
end = m_map.equal_range(s).second;
for(m = beg;m != end;m++)
cout<<m->first<<"--"<<m->second<<endl;
return ;
} /*
中国--50
中国--55
中国--60
美国--30
美国--20
美国--10
中国--50
中国--55
中国--60
请按任意键继续. . .
*/
map_multimap的更多相关文章
随机推荐
- 【C++】static关键字有哪些用法?其主要作用是什么?
static关键字的用法: 1)将全局变量修饰为静态全局变量 存储在静态存储区,整个程序运行期间一直存在 静态全局变量在声明它的文件之外是不可见的,只要声明它的文件可见,而普通的全局变量则是所有文件可 ...
- Three.js构造一个简单的房间
主要研究three.js在3D场景中基本使用:画一个简单的房子.房子上画门和玻璃.房间内放一个床.定义鼠标事件可以移动场景.动画的使用等. 1.Three.js画的一个简单的房子,模拟地板以及四堵墙 ...
- Kaldi安装
Kaldi是基于C++开发并遵守Apache License v2.0的一款语音识别工具包,是目前最流行的ASR工具之一,本文基于Ubuntu 18.04 LTS介绍了如何安装Kaldi. 首先按照官 ...
- Docker 使用入门 Hello World
结合上一篇的所说的内容:现在安装好了Docker 安装好了就要用嘛,所以,先走一个Hello World docker run ubuntu:15.10 /bin/echo "hello w ...
- @PropertySouce注解 读取 properties文件
https://www.cnblogs.com/whx7762/p/7885735.html 1.@ProtertySource @PropertySouce是spring3.1开始引入的基于java ...
- Ole操作帮助类
/// <summary> /// Ole操作类 /// </summary> public class OleDataBaseHandle { private static ...
- selenium中元素操作之简单的鼠标、键盘操作(三)
1.鼠标操作导入类:ActionChains --鼠标的操作形成一连串的动作链,由selenium的ActionChains类来完成模拟鼠标操作手表操作的过程:1.鼠标的操作,先放到一个列表中2.利用 ...
- shell 遍历目录下的所有文件
dir=/usr/local/nginx/logs for file in $dir/*; do echo $file done //结果 ./test.sh /usr/local/nginx/log ...
- ASP.Net超时时间已到解决办法-
解决办法 1.在代码里面,把未关闭的连接关闭 2.扩大共享池,方法如下: 解决方法可以是修改连接池的连接生存期,因为默认值是60秒,即连接从应用程序被释放后可以在池中保存的时间. 具体操作步骤如下: ...
- SAP Cloud Platform 上CPI的初始化工作
SAP Cloud Platform上的CPI tenant,如果没有正确的初始化,试图使用时会遇到如下错误消息: Insufficient scope for this resourceinsuff ...