vector-erase

////////////////////////////////////////
//      2018/04/16 15:34:21
//      vector-erase

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

int main(){
    vector<int> v(10);

    vector<int>::iterator it;
    for (int i = 0; i < 10; i++){
        v[i] = i;
    }
    copy(v.begin(),v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    // remove first element
    it = v.begin();
    v.erase(it);
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    // remove third element
    it = v.begin()+2;
    v.erase(it);
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    //remove 2 elements from begin to v
    it = v.begin();
    v.erase(it, it + 2);
    copy(v.begin(),v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    return 0;
}

/*
OUTPUT:
    0 1 2 3 4 5 6 7 8 9
    1 2 3 4 5 6 7 8 9
    1 2 4 5 6 7 8 9
    4 5 6 7 8 9
*/ 
原文地址:https://www.cnblogs.com/laohaozi/p/12538043.html