zoukankan      html  css  js  c++  java
  • list-push_back

    ////////////////////////////////////////
    //      2018/04/26 11:14:53
    //      list-push_back
    
    // add an element to the end of the list
    
    #include <iostream>
    #include <list>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    template<class T>
    class Name{
    private:
        T first;
        T last;
    public:
        Name(T f, T l) :first(f), last(l){};
        void print(){
            cout.setf(ios::left);
            cout << setw(15) << first << " " << last << endl;
        }
    };
    
    //========================================
    int main(){
        typedef Name<string> N;
        typedef list<N> L;
        L l;
        L::iterator it;
        N n1(string("Albert"), string("Johnson"));
        N n2("Lana","Vinokur");
    
        l.push_back(n1);
        l.push_back(n2);
    
        // unnamed object
        l.push_back(N("Linda","Bain"));
    
        it = l.begin();
    
        while (it != l.end()){
            (it++)->print();
        }
        cout << endl;
        return 0;
    }
    
    
    /*
    OUTPUT:
        Albert          Johnson
        Lana            Vinokur
        Linda           Bain
    */ 
  • 相关阅读:
    py3学习笔记0(入坑)
    为什么很多PHP文件最后都没有?>
    作业
    凯撒密码、GDP格式化输出、99乘法表
    作业4
    作业3
    turtle库基础练习
    作业2
    作业1
    编译原理有限自动机的构造与识别
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537949.html
Copyright © 2011-2022 走看看