C++ erase 删除序列容器元素

#include 
#include 
#include 
using namespace std;
void display(list &x) {
    list::iterator it=x.begin();
    while (it != x.end()) {
        cout << *it <<" ";
        it++;
    }
    cout << endl;
}

int main() {
    
    int sz[5] = { 4,5,3,2,1 };
    list obL(sz, sz + 5);
    display(obL);

    // overloading erase
    list::iterator it = obL.begin();
    it++;
    it = obL.erase(it);
    display(obL);

    // erase all elements
//  obL.erase(it, obL.end());
    display(obL);
    // clear list of elements

    cout << "before clear size of elements:" << size(obL) << endl;
    obL.clear();
    cout << "after clear size of elements:" << size(obL) << endl;
    system("pause");
    return 0;


}

你可能感兴趣的:(C++ erase 删除序列容器元素)