insert.cpp 352 B

1234567891011121314151617
  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. // insert number 10 before number 3
  9. auto new_pos = v.insert(v.begin() + 2, 10);
  10. // output new array and result of insert call
  11. std::cout << *new_pos << '\n';
  12. std::cout << v << '\n';
  13. }