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