c++ 容器反转并且拷贝到一个新容器中

 

// reverse_copy example
#include <iostream>     // cout
#include <algorithm>    // reverse_copy
#include <vector>       // vector
using namespace std;
int main () {
  int myints[] ={1,2,3,4,5,6,7,8,9};
  vector<int> myvector;

  myvector.resize(9);    // allocate space

  reverse_copy (myints, myints+9, myvector.begin());

  // print out content:
  cout << "myvector contains:";
  for (vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
    cout << ' ' << *it;

  cout << '\n';

  return 0;
}

 

posted @ 2019-05-20 00:41  anobscureretreat  阅读(283)  评论(0编辑  收藏  举报