c++ 数组元素拷贝到容器(copy)

 

#include <iostream>     // cout
#include <algorithm>    // copy
#include <vector>       // vector
using namespace std;
int main () {
    int myints[]={10,20,30,40,50,60,70};
    vector<int> myvector (7);
    
    copy ( myints, myints+7, myvector.begin() );
    
    cout << "myvector contains:";
    for (vector<int>::iterator it = myvector.begin(); it!=myvector.end(); ++it)
        cout << ' ' << *it;
    
    cout << '\n';
    
    return 0;
}

 

posted @ 2018-10-19 11:29  anobscureretreat  阅读(2026)  评论(0编辑  收藏  举报