Reading values from a json file and storing them

I just got started with jsoncpp in my game and I'm using it to store settings and to save the game and I've been able to write to a file, but I haven't been able to read a value from a json file

This is what I have come up with

1
2
3
4
5
6
7
8
9
10
11
12
std::ifstream file("settings.json");

    Json::Value jsonData;
    Json::CharReaderBuilder jsonReader;
    std::string errs;

    file >> jsonData;

    std::cout << jsonData << std::endl;

     const std::string dateString(jsonData["fpscounter"].asString());
     std::cout << dateString << std::endl;


The std::cout << jasonData << std::endl; line works fine and it prints the contents of the file to the console, but std::cout << dateString << std::endl; does not print anything
Last edited on
Maybe check if dateString is empty first and print an error msg?
What's the input file ?
Did you check if file is open ? std::fstream has "is_open()" function that return true if file is open and false if not.
Last edited on
Topic archived. No new replies allowed.