#include <iostream> #include <vector> #include <algorithm>using namespace Std;int main () {//array size 7 int Myints[] = {10,20,30,40,50,60,70}; Container size is 8, there are 8 7 vector<int> myvector (8,7); 1. Copy the 7 numbers in the array to the first position of the container, overwriting the first 7 copies of the container (Myints,myints + 7,myvector.begin ()); for (Vector<int>::iterator it = Myvector.begin (); It! = Myvector.end (); it++) cout<< "" <<*it; cout<<endl; /* * 10 20 30 40 50 60 70 7 *//2. Copy the next 3 digits of the container, copy to the second location/* Copy (Myvector.end () -3,myvector.end (), myvector.b Egin () +1); for (Vector<int>::iterator it = Myvector.begin (); It! = Myvector.end (); it++) cout<< "" <<*it; cout<<endl; * * 10 60 70 7 50 60 70 7 *//3. Using the Copy_backward function, the nature and copy are different, but the same copy_backward (Myvector.end () -3,MYVECTOR.E nd (), Myvector.begin () +4); for (Vector<int>::iterator it = Myvector.begin (); It! = Myvector.end (); it++) cout<< "" <<*it; Cout<<eNdl /* * 7 7 */return 0;}
Examples of C + + copy and Copy_backward usages