vector-resize

////////////////////////////////////////
//      2018/04/18 14:36:16
//      vector-resize

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

using namespace std;

int main()
{
    vector<int> v(5);
    for (int i = 0; i < v.size(); i++){
        v[i] = 2 * i;
    }
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    v.resize(7,100);
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    v.resize(4);
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    return 0;
}


/*
OUTPUT:
    0 2 4 6 8
    0 2 4 6 8 100 100
    0 2 4 6
*/ 
原文地址:https://www.cnblogs.com/laohaozi/p/12538027.html