nlohmann json 将一个数组插入另一个数组
nlohmann json insert an array into another array
我想取这两个数组:
[1, 2, 5]
[3, 4]
并将[3, 4]
插入[1, 2, 5]
的位置2。
结果将如下所示:
[1, 2, 3, 4, 5]
我怎样才能做到这一点?
#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);
}
我想取这两个数组:
[1, 2, 5]
[3, 4]
并将[3, 4]
插入[1, 2, 5]
的位置2。
结果将如下所示:
[1, 2, 3, 4, 5]
我怎样才能做到这一点?
#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);
}