having difficulty to parse a test JSON file with this #1323
-
So I was trying to use this parser to recode my Python program to C++ since it had a slower execution time than C++. However, I still can't get it to build and test my code due to errors, all about #include "json/json.h"
#include <fstream>
std::ifstream sample_file("sample.json", std::ifstream::binary);
sample_file >> sample;
// cout << people; //This will print the entire json object.
// The following lines will let you access the indexed objects.
cout << "Bible version: ";
cout << sample["version"]; // bible version
cout << "Sample verse content";
cout << sample["testaments"][0]["books"][2]["chapters"][1]["verses"][1]["verse"]; //sample bible verse selection from JSON file
cout << "Sample footnote content";
cout << sample["testaments"][0]["books"][2]["chapters"][1]["footnotes"][1]["reference"];
cout << sample["testaments"][0]["books"][2]["chapters"][1]["footnotes"][1]["footnotes"]; //sample bible footnote selection from JSON file And here's the console build messages/log:
Btw, the code was based from the answer here from stack overflow: And I'm building this from the GNU GCC compiler in Code::Blocks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It looks like you skipped over some C++ fundamentals. This forum is not a place to learn C++. I think you need to back up a few steps and get some experience with very basic C++ program structure and then come back to this problem. All of those |
Beta Was this translation helpful? Give feedback.
It looks like you skipped over some C++ fundamentals. This forum is not a place to learn C++. I think you need to back up a few steps and get some experience with very basic C++ program structure and then come back to this problem.
All of those
cout
statements need to bestd::cout
, and you need to#include <iostream>
to see the declaration forstd::cout
.The bigger problem is that all those statement need to be inside a function. Statements can't appear at file scope like that in C++ like they can in Python, so C++ thinks you're declaring a variable or function, which is why it's complaining that
cout
doesn't name a type. You need to put all those statements into amain
function and decla…