skip to Main Content

My C++ program below is supposed to read a json file called english.json and display the "title" information.

#include <iostream>
#include <fstream>
#include <json/value.h>
#include <json/reader.h>

using namespace std;

int main()
{
    Json::Value language;
    ifstream language_file("english.json", std::ifstream::binary);
    language_file >> language;

    cout << language["title"] << endl;

    return 0;
}

But when I run the program, I get this error:

E0349 No operator "<<" matches these operands

The program cannot display the information.

I looked at the documentation, but it wasn’t very clear, so I couldn’t find the source of the problem.

I’ve also try to include the json.h file, but it causes other errors related to "unresolved external symbols".

2

Answers


  1. You need to call the correct as* member function to get the actual value from the Json::Value, eg:

    std::cout << language["title"].asString() << 'n';
    //                             ^^^^^^^^^^
    

    Also, you should #include <json/json.h> and link with the jsoncpp library to not get "unresolved external symbols". That way, your program will work without further changes.

    Login or Signup to reply.
  2. Try this :

    cout << language["title"].asString() << endl;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search