C++ multimap 的插入,遍历,删除
2024-08-26 00:39:21
#include <iostream>
#include <map>
#include <string> using namespace std; int main()
{
multimap<string, string> authors; // 插入元素, 引入的头文件是 map
authors.insert(make_pair(
string("Evin"), // 这个是 Key
string("Hi"))); authors.insert(make_pair(
string("Evin"), // 跟上面的一样,是同一个key
string("Hello"))); typedef multimap<string, string>::const_iterator mmap_cit; // 第一种遍历方式
mmap_cit beg = authors.lower_bound("Evin");
mmap_cit end = authors.upper_bound("Evin"); while(beg != end)
{
cout<<beg->second<<endl;
++beg;
} // 另外一种遍历方式
pair<mmap_cit, mmap_cit> pos = authors.equal_range("Evin"); while(pos.first != pos.second)
{
cout<<pos.first->second<<endl;
++pos.first;
} cout<<authors.erase("Evin")<<endl; // erase 返回删除的元素个数 return 0;
}
利用 multimap 能够做到一个key, 同一时候相应多个value
最新文章
- css3 rem的用法
- yum -y upgrade 和 yum -y update 区别
- Innodb行锁源码学习(一)
- PDP 有多种定义,具体哪一种还需研究!!!!
- susy-Toolkit 之翻译
- c语言中static 用法总结(转)
- Python中的List,Tuple,Dic,Set
- Mac OS X下Maven的安装与配置
- PHP 字符串处理 总结
- springMVC项目异步处理请求的错误Async support must be enabled on a servlet and for all filters involved in async
- php中curl远程调用获取数据
- MySQL 报错 _DATA_TYPE_INVALID_
- 学习EtherCAT的感想
- JS 最简单数组去重
- 一些简单的ajax的特点,方法、属性。以及ajax的创建 请求
- AngularJS学习之旅—AngularJS 表达式(二)
- java数据库导入excel数据
- Odoo 8 Graph 视图 之 雷达图 (Radar\Spider)
- sql server 清除数据库中所有表的数据
- P<;0.05就够了?还要校正!校正!3个方法献上
热门文章
- [Angular 2] *ngFor with index
- windows下php+apache+mysql环境搭建
- Linux驱动设备中的并发控制
- 函数返回char* 的解决方案
- Hibernate Validation各注解的用法
- jquery之onchange事件2
- 黑马程序员——HTML语言
- HTML5框架、背景和实体、XHTML的使用规范
- (转)使用Microsoft Web Application Stress Tool对web进行压力测试
- 3.Android Studio系列教程3——快捷键