zoukankan      html  css  js  c++  java
  • 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
    */
  • 相关阅读:
    MyBatis初学者配置
    hibernate错题解析
    Hibernate二级缓存配置
    Open Session In View
    Hibernate延迟加载Lazy
    ThreadLocal
    HQL基础查询语句
    Hibernate中saveOrUpdate()和merge()的区别
    springmvc的类型转换
    springmvc的初始化参数绑定
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537830.html
Copyright © 2011-2022 走看看