zoukankan      html  css  js  c++  java
  • 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
    */ 
  • 相关阅读:
    将excel里的有效数据提取出来
    基础二
    状态码
    基础(一)
    爬虫页面
    交集,并集,差集,函数
    魔法和运算器
    Java接口
    Java封装
    Java抽象类
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12538044.html
Copyright © 2011-2022 走看看