list-pop_front

////////////////////////////////////////
//      2018/04/26 11:08:31
//      list-pop_front

// removes the first elements
#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;

    while (!l.empty()){
        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/12537953.html