swap__reference.cpp 372 B

123456789101112131415161718
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create two JSON values
  7. json j1 = {1, 2, 3, 4, 5};
  8. json j2 = {{"pi", 3.141592653589793}, {"e", 2.718281828459045}};
  9. // swap the values
  10. j1.swap(j2);
  11. // output the values
  12. std::cout << "j1 = " << j1 << '\n';
  13. std::cout << "j2 = " << j2 << '\n';
  14. }