c++ 容器切片反转次序(拷贝到新容器)
code:
// rotate_copy algorithm example #include <iostream> // cout #include <algorithm> // rotate_copy #include <vector> // vector using namespace std; int main () { int myints[] = {10,20,30,40,50,60,70}; vector<int> myvector(7); rotate_copy(myints,myints+3,myints+7,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; }
输出
myvector contains: 40 50 60 70 10 20 30