• multimap-insert


    ////////////////////////////////////////
    //      2018/05/04 17:12:45
    //      multimap-insert
    
    // insert elements into the maltimap
    
    #include <iostream>
    #include <map>
    #include <string>
    
    using namespace std;
    
    int main(){
        typedef multimap<int, char, less<char>> M;
        typedef M::value_type v_t;
    
        M m1, m2;
        char ch = 'A';
        for (int i = 0; i < 3; i++){
            m1.insert(v_t(i+1,ch+i));
            m2.insert(v_t(i+4,ch+i+3));
        }
    
        cout << "m1:" << endl;
        M::iterator it = m1.begin();
        while (it != m1.end()){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
    
        cout << "m2:" << endl;
        it = m2.begin();
        while (it != m2.end()){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
    
        // insert new element
        m1.insert(v_t(5,'E'));
    
        it = m2.find(6);
        // insert element pointed by it
        m1.insert(*it);
    
        cout << "m1:" << endl;
        it = m1.begin();
        while (it != m1.end()){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
    
        // insert the range of elements
        m1.insert(m2.begin(), m2.end());
    
        cout << "m1:" << endl;
        it = m1.begin();
        while (it != m1.end()){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
    
        return 0;
    }
    
    
    /*
    OUTPUT:
        m1:
        1-A
        2-B
        3-C
        m2:
        4-D
        5-E
        6-F
        m1:
        1-A
        2-B
        3-C
        5-E
        6-F
        m1:
        1-A
        2-B
        3-C
        4-D
        5-E
        5-E
        6-F
        6-F
    */
  • 相关阅读:
    使用 Vite 提供的常见模板创建项目
    git 上传空目录,并忽略该空目录中产生的文件变更
    SCL
    Python中时间相关的操作
    rpm的使用
    configparser
    安全随机数
    sqlite3
    多线程threading
    python小杂记
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537830.html
Copyright © 2020-2023  润新知