What is the easiest way to parse a json file using rapidjson?

  c++, json, parsing, rapidjson

So I am just getting familiar with rapidjson.h but I can’t find this one basic piece of example code of parsing the *.json file.

I found the official turorial.
But here however they parse the json stored in a C string. I know how this string is supposed to look like but I’m lazy to make a custom Parser just to convert my file to this string. I mean I was kinda hoping that rapidjson is supposed to do that for me. Please correct me if I’m wrong.

The closest thing I found to what I need is here How to read json file using rapidjson and output to std::string?

Therefore I was really surprised that I can’t just do something like this (with *.json file being in the same folder as my program):

rapidjson::Document d;
d.Parse("myJson.json");

My 1. question is:

Do I have to use std::ifstream and rapidjson::IStreamWrapper to get my Document like in the example above and what other as simple as possible alternatives there are?

My 2. question is: (this one would be much easier to ask if i could comment the post above)

What does the R mean in std::ifstream ifs { R"(C:TestTest.json)" }; and how do I change the C:TestTest.json string to const char* variable?

Because this isn’t working.

const char* str = "C:TestTest.json";
std::ifstream ifs { R"(str)" }; //error
std::ifstream ifs { R(str) }; //error
std::ifstream ifs{ (str) }; //ok but I don't like it

Source: Windows Questions C++

LEAVE A COMMENT