insert__range.cpp 473 B

1234567891011121314151617181920
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create a JSON array
  7. json v = {1, 2, 3, 4};
  8. // create a JSON array to copy values from
  9. json v2 = {"one", "two", "three", "four"};
  10. // insert range from v2 before the end of array v
  11. auto new_pos = v.insert(v.end(), v2.begin(), v2.end());
  12. // output new array and result of insert call
  13. std::cout << *new_pos << '\n';
  14. std::cout << v << '\n';
  15. }