Reputation: 11
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".
Upvotes: -1
Views: 124
Reputation: 117298
The operator<<
overload you are trying to use is declared in json/writer.h
so you need include that too, or replace all your json/*
includes with #include <json/json.h>
, which will include all the rest of the jsoncpp header files.
Another option is to call the correct as*
member function to get the actual value from the Json::Value
, eg:
std::cout << language["title"].asString() << '\n';
// ^^^^^^^^^^
You also need to link with the jsoncpp
library to not get "unresolved external symbols".
Upvotes: 3
Reputation: 1
Try this :
cout << language["title"].asString() << endl;
Upvotes: 0