streamWrite.cpp 500 B

1234567891011121314151617181920212223
  1. #include "json/json.h"
  2. #include <iostream>
  3. /** \brief Write the Value object to a stream.
  4. * Example Usage:
  5. * $g++ streamWrite.cpp -ljsoncpp -std=c++11 -o streamWrite
  6. * $./streamWrite
  7. * {
  8. * "Age" : 20,
  9. * "Name" : "robin"
  10. * }
  11. */
  12. int main() {
  13. Json::Value root;
  14. Json::StreamWriterBuilder builder;
  15. const std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
  16. root["Name"] = "robin";
  17. root["Age"] = 20;
  18. writer->write(root, &std::cout);
  19. return EXIT_SUCCESS;
  20. }