swap__string_t.cpp 438 B

1234567891011121314151617181920
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create a JSON value
  7. json value = { "the good", "the bad", "the ugly" };
  8. // create string_t
  9. json::string_t string = "the fast";
  10. // swap the object stored in the JSON value
  11. value[1].swap(string);
  12. // output the values
  13. std::cout << "value = " << value << '\n';
  14. std::cout << "string = " << string << '\n';
  15. }