-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting std::invalid_argument: stream error when following example #429
Comments
To clarify, I'm using version 2.0.10 of |
Additionally, this is the contents of {
"Items": {
"Food": {
"Apple": {
"Heal": 10,
"MaxStack": 20
},
"Bread": {
"Heal": 20,
"MaxStack": 20
}
}
}
} |
The To fix this, you can add those two lines right after the input_json.clear(); // clear error/eof flags
input_json.seekg(0); // go back to the beginning of the file
input_json >> json_obj; However there is a better way to parse a stream with this library: std::ifstream ifs{"test.json"};
auto parsed_json = json::parse(ifs);
std::cout << parsed_json.dump() << std::endl; |
Ah, of course. Thanks for the tip. I went with the |
I hope the error messages become clearer when #244 is merged. |
I'm new to the library, but following the example on the base README:
I'm getting the following error:
My code is as follows:
I've verified that
input_file
is ok, since I can iterate through the lines and print them out in thewhile
loop. As soon as I addinput_json >> json_obj
I get the above exception.Am I doing something wrong? Haven't been able to find any doc that says this shouldn't work.
The text was updated successfully, but these errors were encountered: