第四十五节 C++ STL(标准模板库)-映射类std::map std::multimap std::unordered_map std::unordered_multimap

本文介绍了C++ STL中的映射类,包括std::map和std::multimap的基本操作,它们是键值对容器,支持根据键查找值。std::map存储唯一的键并按升序排序,而std::multimap允许键重复。另外,还提及了使用散列函数排序的std::unordered_map和std::unordered_multimap,它们同样提供键值对存储,但键的唯一性和排序方式不同。
摘要由CSDN通过智能技术生成

map的操作与set类似,操作可参考上一节,这里仅介绍基本操作

映射类: 为key-value(键-值)对容器, 支持根据key查找value, 如根据int可查找对应的string

std::map: 存储唯一的键, 默认从小到大排序

std::mulitmap: 可存储重复的键 , 默认从小到大排序

 std::unordered_map: 用散列函数排序,键唯一

 std::unordered_multimap:用散列函数排序,键可重复

#include <iostream>    
#include <map>

using namespace std;

template <typename T1>
void DisplayContent(const T1 input) {
	int index = 0;

	for (auto Iterator = input.begin(); Iterator != input.end(); ++Iterator) {
		index = std::distance(input.begin(), Iterator);
		cout << " [" << index << "] = ";
		printf("first = %d, second = %s\n",
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值