Examples of C + + copy and Copy_backward usages

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.