栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【数据结构】map/unordered

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【数据结构】map/unordered

目录
  • 一、内容描述
  • 二、实现方案
  • 三、结果


一、内容描述

本文记录了map/unordered_map的几种遍历方式,使用新的C++语法让map/unordered_map的遍历变得简单。


二、实现方案

实现代码如下:

//map unordered_map 遍历 

#include
#include
#include
#include

using namespace std;

int main(){
    unordered_map hashmap;
    hashmap['a'] = 1;
    hashmap.insert(pair('b',2));
    hashmap['c'] = 3;
    // 方式一
    cout<<"方式1:"<::iterator item = hashmap.begin(); item != hashmap.end(); item++){
        cout<first<<" "<second<
        cout<first<<" "<second<
        cout< 

三、结果
方式1:
c 3
b 2
a 1
方式2:
c 3
b 2
a 1
方式3:
c 3
b 2
a 1

如果本文能给你带来帮助的话,点个赞鼓励一下作者吧!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/968792.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号