C++基础 -44- STL库之map容器

map是一种关联式容器,数据的存放方式为键值对(key和value)

map的定义格式

cpp 复制代码
 map<string, int> ccc;

往map容器插入数据

cpp 复制代码
 ccc.insert(pair<string, int>("rlxy", 18));

使用下标也可以插入数据

cpp 复制代码
	ccc["heelo"] = 10;
	ccc["world"] = 20;

遍历map容器的数据

cpp 复制代码
    for (auto i = ccc.begin(); i != ccc.end(); i++)
    {
        cout << i->first << endl;
        cout << i->second << endl;
    }

查找值

cpp 复制代码
    auto i = ccc.find("rlxy");
    cout << i->second << endl;
相关推荐
2401_884602271 天前
程序人生-Hello’s P2P
c语言·c++
初中就开始混世的大魔王1 天前
2 Fast DDS Library概述
c++·中间件·信息与通信
MediaTea1 天前
Python:collections.Counter 常用函数及应用
开发语言·python
LawrenceLan1 天前
37.Flutter 零基础入门(三十七):SnackBar 与提示信息 —— 页面反馈与用户交互必学
开发语言·前端·flutter·dart
李昊哲小课1 天前
Python json模块完整教程
开发语言·python·json
易醒是好梦1 天前
Python flask demo
开发语言·python·flask
娇娇yyyyyy1 天前
C++基础(6):extern解决重定义问题
c++
Neteen1 天前
【数据结构-思维导图】第二章:线性表
数据结构·c++·算法