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;
相关推荐
不想写代码的星星13 小时前
std::function 详解:用法、原理与现代 C++ 最佳实践
c++
樱木Plus2 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit4 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_5 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星6 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛7 天前
delete又未完全delete
c++
端平入洛8 天前
auto有时不auto
c++
郑州光合科技余经理9 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1239 天前
matlab画图工具
开发语言·matlab
dustcell.9 天前
haproxy七层代理
java·开发语言·前端