emplace_back.cpp 452 B

123456789101112131415161718192021222324
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create JSON values
  7. json array = {1, 2, 3, 4, 5};
  8. json null;
  9. // print values
  10. std::cout << array << '\n';
  11. std::cout << null << '\n';
  12. // add values
  13. array.emplace_back(6);
  14. null.emplace_back("first");
  15. null.emplace_back(3, "second");
  16. // print values
  17. std::cout << array << '\n';
  18. std::cout << null << '\n';
  19. }