Skip to content

Instantly share code, notes, and snippets.

@steveobbayi
Created March 31, 2016 17:21
Show Gist options
  • Save steveobbayi/2742e6ff8401512f38dcabe255935f11 to your computer and use it in GitHub Desktop.
Save steveobbayi/2742e6ff8401512f38dcabe255935f11 to your computer and use it in GitHub Desktop.
vector<int> v1 = {3,4};
vector<int> v2 = {1,2,5,6};
// Get the position of "5" in the vector and store it in i
vector<int>::iterator i = find(v2.begin(), v2.end(), 5);
//Now we use the insert iterator to add all elements in
//v1 to v2 at the position of i
insert_iterator<vector<int>> ins_i(v2, i);
copy(v1.begin(), v1.end(), ins_i);
// v2 is now {1,2,3,4,5,6}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment