nlohmann json将一个数组插入另一个数组

问题描述 投票:0回答:1

我想采用这两个数组:

[1, 2, 5]

[3, 4]

并将[3, 4]插入[1, 2, 5]的位置2。结果将如下所示:

[1, 2, 3, 4, 5]

我该如何实现?

c++ json nlohmann-json
1个回答
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);
}
© www.soinside.com 2019 - 2024. All rights reserved.