c++ map

unordered_map

#include <iostream>
#include <string>
#include <unordered_map>

int main()
{
   
    // 创建包含三个字符串的(映射到字符串的)unordered_map
    std::unordered_map<std::string, std::string> u =
            {
   
                    {
   "red", "#FF0000"},
                    {
   "green", "#00FF00"},
                    {
   "blue", "#0000FF"}
            };

    map<string,string> xs;
    xs.insert(make_pair("555","44444"));
    xs["222"] ="aaa";
    xs["333"] ="aaaa";
    for (auto x:xs) {
   
        cout<<x.first<<"\t"<<x.second<<endl;
    }
}

find方法查找

map<string,string> mm;
mm["12"] ="12";
mm["13"] ="13";
mm["14"] ="14";
auto iterator = mm.find("13");
if (iterator != mm.end()){
   
    cout<< iterator->first<<"\t"<<iterator->second<<endl;
}

在这里插入图片描述

相关推荐

  1. Linux/<span style='color:red;'>Cap</span>

    Linux/Cap

    2023-12-12 18:22:05      47 阅读
  2. Cmap数据以及L1000介绍

    2023-12-12 18:22:05       67 阅读
  3. chap6 RNN

    2023-12-12 18:22:05       28 阅读
  4. Nacos的CAP定理

    2023-12-12 18:22:05       62 阅读
  5. CAP与BASE理论

    2023-12-12 18:22:05       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-12 18:22:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-12 18:22:05       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-12 18:22:05       82 阅读
  4. Python语言-面向对象

    2023-12-12 18:22:05       91 阅读

热门阅读

  1. 《Effective C++》条款33

    2023-12-12 18:22:05       59 阅读
  2. 揭秘平台工程如何减轻工程师的认知负荷

    2023-12-12 18:22:05       56 阅读
  3. TypeScript 第二节:基础类型

    2023-12-12 18:22:05       53 阅读
  4. 安卓apk逆向

    2023-12-12 18:22:05       72 阅读
  5. Go map 大小

    2023-12-12 18:22:05       61 阅读
  6. Docker容器与镜像

    2023-12-12 18:22:05       47 阅读