一、内容描述
本文记录了map/unordered_map的几种遍历方式,使用新的C++语法让map/unordered_map的遍历变得简单。
二、实现方案
以unordered_map
为例,map
同理,只需要将以下代码部分的unordered_map
修改为map
即可,实现代码如下:
//map unordered_map 遍历
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
int main(){
unordered_map<char, int> hashmap;
hashmap['a'] = 1;
hashmap.