From 5eb3689c9985f28b46651f547b9b32d55b4a07b5 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 22 Apr 2016 22:23:35 +0200 Subject: Handle input stream EOF --- justify.cc | 8 ++++++-- src/line_accumulator.cc | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/justify.cc b/justify.cc index 8120ded..c417dfd 100644 --- a/justify.cc +++ b/justify.cc @@ -81,8 +81,12 @@ bool process(const boost::program_options::variables_map& variables) { justify::LineAccumulator acc{line_length, line_offset}; std::string token; - while ( std::cin >> token ) { - acc(token); + while ( std::cin.good() ) { + if ( std::cin >> token ) { + acc(token); + } else { + return true; + } } return true; diff --git a/src/line_accumulator.cc b/src/line_accumulator.cc index 4398c50..9ce389b 100644 --- a/src/line_accumulator.cc +++ b/src/line_accumulator.cc @@ -149,7 +149,7 @@ void LineAccumulator::justify() { std::for_each( indizes.begin(), indizes.begin() + this->getMissing(), - [&](std::uint8_t x) { + [&](const std::uint8_t x) { this->tokens_[x].second += 1; this->length_ += 1; } -- cgit v1.2.3