nlohmann json вставить массив в другой массив - PullRequest
0 голосов
/ 24 февраля 2020

Я хочу взять эти два массива:

[1, 2, 5]

[3, 4]

и вставить [3, 4] в положение 2 из [1, 2, 5]. Результат будет выглядеть так:

[1, 2, 3, 4, 5]

Как мне этого добиться?

1 Ответ

1 голос
/ 24 февраля 2020
#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);
}
...