c++ stl --copy

来源:互联网 发布:splice视频编辑软件 编辑:程序博客网 时间:2024/04/30 12:47
#include <iostream>#include <string>#include <algorithm>#include <vector>#include <iterator>using namespace std;int main(){/*vector<string> ve;copy(istream_iterator<string>(cin),     istream_iterator<string>(),             back_inserter(ve));sort(ve.begin(),ve.end());copy(ve.begin(),ve.end(),ostream_iterator<string>(cout,"\t"));*/vector<int> ve;for(int i = 0; i< 9; i++){ve.push_back(i);}copy(ve.begin(),ve.end(),ostream_iterator< int >(cout, "\t"));cout << ve.size() <<endl;//remove(ve.begin(),ve.end(),3);//ve.erase(3); //errorcopy(ve.begin(),ve.end(),ostream_iterator< int >(cout, "\t"));cout << ve.size() <<endl;cout <<endl;cout << "modify------------------" <<endl;vector<int>::iterator newend =remove(ve.begin(),ve.end(),3);copy(ve.begin(),newend,ostream_iterator< int >(cout, "\t"));cout << endl;cout <<"distance" << distance(newend, ve.end()) << endl;cout << endl;ve.erase(newend, ve.end());copy(ve.begin(),newend,ostream_iterator< int >(cout, "\t"));cout << endl;}