Replace part of a vector with another vector

I have a vector of size 20 and a second size of 5. I want to replace elements 11-15 with the first vector with the second vector. I can do this by removing these elements from the first vector and inserting the second vector. Is there any other way to do this, possibly using an assignment?

+6
source share
1 answer

You can use std::copy :

 #include <algorithm> // for std::copy std::copy(v2.begin(), v2.end(), v1.begin()+10); 

where v2 is a vector of size 5 and v1 is a vector of size 20.

+6
source

Source: https://habr.com/ru/post/949434/


All Articles