list-size

////////////////////////////////////////
//      2018/04/27 7:22:00
//      list-size

#include <iostream>
#include <list>
#include <algorithm>
#include <iterator>

using namespace std;

int main(){
    list<int> l(5, 0);
    copy(l.begin(), l.end(), ostream_iterator<int>(cout," "));
    cout << endl;

    cout << "Size of list = " << l.size() << endl;

    int size = l.size();

    for (int i = 0; i < size; i++){
        l.pop_front();
        cout << "Size of list = " << l.size() << endl;
    }

    return 0;
}

/*
OUTPUT:
    0 0 0 0 0
    Size of list = 5
    Size of list = 4
    Size of list = 3
    Size of list = 2
    Size of list = 1
    Size of list = 0
*/
原文地址:https://www.cnblogs.com/laohaozi/p/12537935.html