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;
相关推荐
临床数据科学和人工智能兴趣组7 小时前
在R语言中, 使用 as.factor() 函数转换数值型变量
开发语言·r语言
andyweike10 小时前
php笔记
开发语言·笔记·php
蒸蒸yyyyzwd10 小时前
秋招学习笔记 day46
c++·八股
Circ.11 小时前
Python 调试 Litellm 本地大模型接口:模型列表与对话接口实操踩坑记录
开发语言·python
现任明教教主~13 小时前
Thinkphp站群蜘蛛池SaaS系统YanyvSEO含多用户/积分/六大引擎计费/易支付对接
java·开发语言·spring
Zhou14113613 小时前
SpringSecurity_02_授权与高级功能
开发语言·python
码匠许师傅14 小时前
【C++三方组件】cpp-httplib:一个头文件起 HTTP 服务
开发语言·c++·http
无名猿14 小时前
new/delete 与 malloc/free:为什么绝对不能混用
c++·内存管理·现代c++·踩坑记录