#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的更多相关文章

随机推荐

  1. python3.5+tornado学习

    python3.5的安装 python官网下载地址:https://www.python.org/ 自行下载最新版本 下载pip包或者easy_install 后缀为.gz格式 地址:https:// ...

  2. 图片懒加载--lazyload.js的用法

    这几天公司的项目已经完成的差不多了,只剩下各种优化问题.今天着重于图片加载的优化.当一个页面需要下拉很长而且又有过多的图片要加载时,就会发生很多http请求,就会拉慢网页加载速度,用户体验不友好.怎么 ...

  3. asp.net中的html標籤runat=server時的映射

    asp.net中的html控制項runat=server時的映射 1.標準xhtml標籤:http://blog.csdn.net/TangZhongxin/archive/2009/07/31/43 ...

  4. 测试代码的练习2——python编程从入门到实践

    11-3 雇员:编写一个名为Employee的类,其方法__init__() 接受名.姓和年薪,并将它们都存储在属性中.编写一个名为give_raise()的方法,它默认将年薪增加5000美元,但也能 ...

  5. Linux系统 关机/重启/用户切换/注销,用户管理(用户创建/修改,用户组增加/删除),Linux中 / 和 ~ 的区别

    1.关机/重启命令 shutdown命令 shutdown -h now :立即关机 shutdown -h 1 :1分钟后关机 shutdown -r now :立即重启 shutdown -r 1 ...

  6. 配置安全web服务

    为站点 http://system1.group8.example.com 配置TLS加密: 1.一个已签名证书从 http://server.group8.example.com/pub/tls/c ...

  7. Map 集合按字母排序方法

    @Testpublic void testMapSort() { Map<String, String> map = new HashMap<>(); map.put(&quo ...

  8. java之hiberante之集合映射之list映射

    这篇讲解 集合映射之List映射 1.通常对于集合,在hibernate中的处理都是使用set来完成.但是hibernate也提供了对于其他几种集合的映射. 在这里实现List的映射,List是有序的 ...

  9. 基于Text-CNN模型的中文文本分类实战

    Text-CNN 1.文本分类 转眼学生生涯就结束了,在家待就业期间正好有一段空闲期,可以对曾经感兴趣的一些知识点进行总结. 本文介绍NLP中文本分类任务中核心流程进行了系统的介绍,文末给出一个基于T ...

  10. centos7 上Docker安装与启动

    1.  docker  centos 文档地址 https://docs.docker.com/install/linux/docker-ce/centos/ 2. 安装环境说明: docker社区版 ...