c++ inseter 用法

来源:互联网 发布:电子地图 数据采集 编辑:程序博客网 时间:2024/05/01 06:58

#include<iostream>
#include<cmath>
#include<iterator>
#include<vector>
using namespace std;

int main()
{
    vector<int> a;
    int i;
    for(i = 1; i < 10; i++)a.push_back(i);
   
    vector<int> b,c;

    b.push_back(-1);
    c.push_back(-1);
   
    copy(a.begin(), a.end(), b.begin() );
    copy(a.begin(), a.end(), inserter(c, c.begin()) );
   
    cout << "normal copy:";
    copy(b.begin(), b.end(), ostream_iterator<int>(cout, " ") );
    cout <<endl;
   
   
    cout << "inserter copy:";
    copy(c.begin(), c.end(), ostream_iterator<int>(cout, " ") );
    cout << endl;
   

    system("pause");