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
You need to call the correct
as*
member function to get the actual value from theJson::Value
, eg:Also, you should
#include <json/json.h>
and link with thejsoncpp
library to not get "unresolved external symbols". That way, your program will work without further changes.Try this :