map/multimap,set/multiset都是关联容器。定义时,set与map不同的地方在于:set仅有key_type类型,它的value_type也就是key_type;set没有下标操作。
#include "stdafx.h"
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
struct ltstr{ // when the first arg of multimap is a user-definded type,we must provide a method for ordering
bool operator()(const char*s1,const char *s2) const{
return strcmp(s1,s2)>0;
}
};
int main()
{
multimap<const char*,int,ltstr> m;
multimap<const char*,int,ltstr>::iterator it;
m.insert(pair<const char* const,int>("a",1));
m.insert(pair<const char* const,int>("c",2));
m.insert(pair<const char* const,int>("b",3));
m.insert(pair<const char* const,int>("b",4));
m.insert(pair<const char* const,int>("a",5));
cout<<"num of elem with key a:"<<m.count("a")<<endl;
cout<<"num of elem with key b:"<<m.count("b")<<endl;
cout<<"num of elem with key c:"<<m.count("c")<<endl;
cout<<"elem in m:"<<endl;
for(it=m.begin();it!=m.end();++it)
cout<<" ["<<(*it).first<<","<<(*it).second<<"]"<<endl;
return 0;
}
分享到:
相关推荐
C++ multimap和map所支持的操作相同(除了multimap不支持下标运算),但是multimap允许重复的元素。 完整程序代码: /*请务必运行以下程序后对照阅读*/ ///头文件依旧是map #include #include #include using ...
C++中map容器提供一个键值对容器,map与multimap差别仅仅在于multiple允许一个键对应多个值。本文主要总结一下map基本用法和嵌套用法示例。 一、map基本用法 1. 头文件 代码如下:#include 2. 定义 代码如下:map...
通过multimap进行信息的插入 key(部门编号) value(员工) 分部门显示员工信息 实现步骤: 创建10名员工,放到vector中 遍历vector容器,取出每个员工,进行随机分组 分组后,将员工部门编号作为key,具体员工作为...
c++ vs2019 cpp20规范的STL库的map与multimap源码分析
一共四个doc文件,list综合实例、multimap和map的实例、set和multiset的综合实例、vector综合实例
C++使用multimap实现tlv,支持重复tlv。实现代码+Makefile
c++实现tlv的编解码,使用multimap封装tlv容器,接口与stl标准容器保持一致,可读性和扩展性较好。
c++简易定时任务引擎,原理简单,接口使用简单,通用。 支持指定任务执行次数。 包含使用示例。 启动定时器引擎Start(); 停止定时器引擎bool Stop(); 添加定时器( 不同的回调里面不用考虑dwTimerID重复的问题 )bool ...
本程序用c++标准库中的快速排序算法以及容器map和multimap实现了对文件中出现频率靠前的单词进行了统计,至于文件大小取决于你机器所剩的内存数,如果文件数据时海量的(上亿)则本程序可能不适合,需要按照海量数据...
类似于STL的map、set、multimap和multiset模板,C++ B-tree也提供了btree_map、btree_set、btree_multimap和btree_multiset等模板。 B-tree(多路搜索树,并不是二叉的)是一种常见的数据结构。使用B-tree结构...
Chapter 23: Associative Containers–set, multiset, map and multimap 559 Chapter 24: Bit Sets 578 Chapter 25: Algorithms 589 REFERENCES 625 APPENDIX–A ASCII CHARACTER CODE SET 627 APPENDIX–B C++ ...
10.2.9Map和multimap容器 118 10.2.10容器共性机制研究 123 10.2.11其他 124 10.3算法 125 10.3.1算法基础 125 10.3.2STL算法中函数对象和谓词 138 10.3.3常用的遍历算法 148 10.3.4常用的查找算法 152 10.3.5常用的...
【原书名】 C++ Primer (4th Edition) 【原出版社】 Addison Wesley/Pearson 【作者】 (美)Stanley B.Lippman,Josée LaJoie,Barbara E.Moo 【译者】 李师贤 蒋爱军 梅晓勇 林瑛 【丛书名】 图灵计算机科学丛书 ...
【内容简介】 C++ STL标准模板库在数据结构和算法的实践领域发挥着重要的作用。本书共分5篇26章,以“C++编程技术→C++ STL...第14章 multimap多重映照容器 第15章 hash_set哈希集合容器 第16章 hash_map哈希映照容器
本资源是使用XMind总结C++中关联容器的使用,关联容器包括map,set,multimap,multiset。内含相关的操作及构造函数,代码片段演示
第1章 C++编程技术 2 1.1 类和对象 2 1.2 类的继承 5 1.3 函数重载 5 1.4 访问控制 7 1.5 操作符重载 8 1.6 显式类型转换 9 1.7 异常处理 13 1.8 名字空间 17 1.9 友员函数 20 1.10 内联函数 ...
C++中map容器提供一个键值对容器,map与multimap差别仅仅在于multiple允许一个键对应多个值。
The C++ Standard Library A Tutorial and Reference (2nd Edition)+cppstdlib-code.zip C++标准库(第二版)英文版.pdf 非扫描版+源代码 Prefaceto the SecondEdition xxiii Acknowledgments for the Second...
C++中的容器类包括“顺序存储结构”和“关联存储结构”,前者包括vector,list,deque等;后者包括set,map,multiset,multimap等。 常用函数介绍等. 若需要存储的元素数在编译器间就可以确定,可以使用数组来...