• map-constructors


    ////////////////////////////////////////
    //      2018/04/30 11:55:43
    //      map-constructors
    
    #include <iostream>
    #include <map>
    
    using namespace std;
    
    int main(){
        typedef map<int, char, less<int>> M;
        M m1;
    
        m1.insert(M::value_type(2,'B'));
        m1.insert(M::value_type(3,'C'));
        m1.insert(M::value_type(1,'A'));
    
        M::iterator it = m1.begin();
        cout << "m1:" << endl;
    
        while (it != m1.end()){
            cout << (*it).first << "-" << (*it).second << endl;
            it++;
        }
        cout << endl;
    
        // copy constructor
        M m2(m1);
        it = m2.begin();
        cout << "m2:" << endl;
        while (it != m2.end()){
            cout << (*it).first << "-" << (*it).second << endl;
            it++;
        }
        cout << endl;
    
        M m3(m2.begin(), m2.end());
        it = m3.begin();
        cout << "m3:" << endl;
        while (it != m3.end()){
            cout << (*it).first << "-" << (*it).second << endl;
            it++;
        }
        return 0;
    }
    
    /*
    OUTPUT:
        m1:
        1-A
        2-B
        3-C
    
        m2:
        1-A
        2-B
        3-C
    
        m3:
        1-A
        2-B
        3-C
    */ 
  • 相关阅读:
    2019春第八周作业
    2019春第七周作业
    第六周作业
    币值转换
    打印沙漏
    秋季学期学习总结
    人生影响最大的三位老师
    自我介绍
    2018秋季学习总结
    自己
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537866.html
Copyright © 2020-2023  润新知