zoukankan      html  css  js  c++  java
  • B00010 map

    这是一个有关map的例子程序,代码来自:std::map::emplace - cppreference.com

    源程序如下:

    /* B00010 map */
    
    #include <iostream>
    #include <utility>
    #include <string>
    #include <map>
    
    using namespace std;
    
    int main()
    {
        std::map<std::string, std::string> m;
    
        // uses pair's move constructor
        m.emplace(std::make_pair(std::string("a"), std::string("a")));
    
        // uses pair's converting move constructor
        m.emplace(std::make_pair("b", "abcd"));
    
        // uses pair's template constructor
        m.emplace("d", "ddd");
    
        // uses pair's piecewise constructor
        m.emplace(std::piecewise_construct,
                  std::forward_as_tuple("c"),
                  std::forward_as_tuple(10, 'c'));
        // as of C++17, m.try_emplace("c", 10, 'c'); can be used
    
        for (const auto &p : m) {
            std::cout << p.first << " => " << p.second << '
    ';
        }
    }

    运行结果如下:

    a => a
    b => abcd
    c => cccccccccc
    d => ddd


  • 相关阅读:
    UnityShader
    Unity
    Tools
    linux下解压命令
    进程 同步、互斥
    I/O模型
    jclass jobject
    javah javap
    IDA 结构体
    Windows CSRSS API List (NT/2000/XP/2003/Vista/2008/7/2012/8)
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7564745.html
Copyright © 2011-2022 走看看