-1

I want to take these two arrays:

[1, 2, 5]

[3, 4]

and insert the [3, 4] into position 2 of [1, 2, 5]. The result would look like this:

[1, 2, 3, 4, 5]

How can I achieve this?

Ank i zle
  • 2,089
  • 3
  • 14
  • 36
  • 3
    You just asked (and got an answer, from me!) this question yesterday... [C++ json insert into array](https://stackoverflow.com/questions/60358607/c-json-insert-into-array) – druckermanly Feb 24 '20 at 00:57

1 Answers1

0
#include <iostream>
#include<vector>
#include<iterator>
#include<algorithm>

int main() {

    std::vector<int> v1 ={1, 2, 5};
    std::vector<int> v2 ={3,4};

    std::vector<int> v3=v1;//will hold the new one
    v3.insert(v3.begin()+2,v2.begin(),v2.end());
    //To see the result
    std::ostream_iterator<int> printer{std::cout, " "};
    std::copy(v3.begin(),v3.end(), printer);
}
asmmo
  • 6,922
  • 1
  • 11
  • 25