Vector-assign

////////////////////////////////////////
//      2018/04/15 17:30:04
//      Vector-assign

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

using namespace std;

int main(){
    int array[] = { 1, 2, 3, 4, 5 };
    vector<int> v;

    // assign to the "v" the contains of array
    v.assign(array, array + 5);
    // 这里相当于输出
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    // replace v for 3 copies of 100
    v.assign(3, 100);
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    return 0;
}
原文地址:https://www.cnblogs.com/laohaozi/p/12538062.html