Vector-Erase

  • + 0 comments
    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <iterator>
    using namespace std;
    
    int main() {
        vector<int> v;
        int x, a, b;  //x=elem to remove, a and b=range to remove
    
        int size; //size of vector
        cin >> size;
    		
    		//fill vector
        copy_n(istream_iterator<int>(cin), size, back_inserter(v));  
    
        cin >> x;  //insert element to remove
        v.erase(v.begin()+(--x));
    
        cin >> a >> b;  //insert range to remove
        v.erase(v.begin()+(--a), v.begin()+(--b));
    
        cout << v.size() << endl;  //output size of vector
    		
    		//output vect
        copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); 
    		
        return 0;
    }