Skip to content

Commit

Permalink
Use more appropriate istreambuf_iterator in the streaming.cc example
Browse files Browse the repository at this point in the history
Used in the example std::istream_iterator skips whitespace and thus
a parser can produce unexpected reult, e.g.:

 Input: [{"x":"test space","y":20}]
 Output: "testspace",20

std::istreambuf_iterator does not skip whitespace, so is more
appropriate:

 Output: "test space",20

More info:
http://en.cppreference.com/w/cpp/iterator/istream_iterator (see "Notes"
section).
  • Loading branch information
rmisev committed Sep 10, 2017
1 parent 5c1a23c commit 05a0d66
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion examples/streaming.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(void) {
root_context ctx;
std::string err;

picojson::_parse(ctx, std::istream_iterator<char>(std::cin), std::istream_iterator<char>(), &err);
picojson::_parse(ctx, std::istreambuf_iterator<char>(std::cin), std::istreambuf_iterator<char>(), &err);

if (!err.empty()) {
std::cerr << err << std::endl;
Expand Down

0 comments on commit 05a0d66

Please sign in to comment.