c++通用算法-copy

#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
    int a[] = {10,20,30};
    string s[]={"abc","def","hjk","dsaf"};
    const size_t SIZE = sizeof a / sizeof a[0];
    const size_t SIZE_STR = sizeof s / sizeof s[0];
    int b[SIZE];
    string str[SIZE_STR];
    copy(a,a+SIZE,b);
    copy(s,s+SIZE_STR,str);
    for(int i=0;i<SIZE;++i)
        cout<<b[i]<<" ";
    cout << endl;
    for(int i=0;i<SIZE_STR;++i)
        cout << str[i] << " ";
    vector<int> v1,v2;
    v1 = vector<int>(a,a+SIZE);
    //copy(v1.begin(),v1.end(),v2.begin()); 这行在gcc上跑不起来啊
    copy(v1.begin(),v1.end(),back_inserter(v2));
    cout << endl;
    for(vector<int>::const_iterator iter=v2.begin();
                                    iter!=v2.end();
                                    ++iter)
    {
        cout << *iter << " ";
    }
}

10 20 30 
abc def hjk dsaf 
10 20 30

你可能感兴趣的:(C++,c,算法,C#,gcc)