• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  #include "json/json.h"
2  #include <cstdlib>
3  #include <fstream>
4  #include <iostream>
5  /** \brief Parse from stream, collect comments and capture error info.
6   * Example Usage:
7   * $g++ readFromStream.cpp -ljsoncpp -std=c++11 -o readFromStream
8   * $./readFromStream
9   * // comment head
10   * {
11   *    // comment before
12   *    "key" : "value"
13   * }
14   * // comment after
15   * // comment tail
16   */
main(int argc,char * argv[])17  int main(int argc, char* argv[]) {
18    Json::Value root;
19    std::ifstream ifs;
20    ifs.open(argv[1]);
21  
22    Json::CharReaderBuilder builder;
23    builder["collectComments"] = true;
24    JSONCPP_STRING errs;
25    if (!parseFromStream(builder, ifs, &root, &errs)) {
26      std::cout << errs << std::endl;
27      return EXIT_FAILURE;
28    }
29    std::cout << root << std::endl;
30    return EXIT_SUCCESS;
31  }
32