Skip to content

Instantly share code, notes, and snippets.

@steveobbayi
Created May 23, 2016 20:15
Show Gist options
  • Save steveobbayi/fc399e6e59d48664b248a4f6ca2b3719 to your computer and use it in GitHub Desktop.
Save steveobbayi/fc399e6e59d48664b248a4f6ca2b3719 to your computer and use it in GitHub Desktop.
vector<int> src = {2,5,3}; // our source of data
vector<int> dest = {0,0,0,0,0,0,0,0,0,0}; // array to be modified
// Lets copy all of src to dest
copy(src.begin(), src.end(),dest.begin());
// dest is now {2,5,3,0,0,0,0,0,0,0}
// lets copy part of src to dest
copy_n(src.begin(), 2, dest.begin());
// dest is now {2,5,0,0,0,0,0,0,0,0}
//lets copy to the end of dest
copy_backward(src.begin(), src.end(),dest.end());
//dest is now {0,0,0,0,0,0,0,2,5,3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment