 <p>I would at least <em>consider</em> doing this job somewhat differently. Right now, you're reading a word at a time, then putting the words back together until you get to a period.</p> <p>One possible alternative would be to use <code>std::getline</code> to read input until you get to a period, and put the whole string into the vector at once. Code to do the job this way could look something like this:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;algorithm&gt; #include &lt;vector&gt; #include &lt;iterator&gt; int main() { std::vector&lt;std::string&gt; s; std::string temp; while (std::getline(std::cin, temp, '.')) s.push_back(temp); std::transform(s.begin(), s.end(), std::ostream_iterator&lt;std::string&gt;(std::cout, ".\n"), [](std::string const &amp;s) { return s.substr(s.find_first_not_of(" \t\n")); }); } </code></pre> <p>This does behave differently in one circumstance--if you have a period somewhere <em>other</em> than at the end of a word, the original code will ignore that period (won't treat it as the end of a sentence) but this will. The obvious place this would make a difference would be if the input contained a number with a decimal point (e.g., <code>1.234</code>), which this would break at the decimal point, so it would treat the <code>1</code> as the end of one sentence, and the <code>234</code> as the beginning of another. If, however, you don't need to deal with that type of input, this can simplify the code considerably.</p> <p>If the sentences might contain decimal points, then I'd probably write the code more like this:</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;algorithm&gt; #include &lt;vector&gt; #include &lt;iterator&gt; class sentence { std::string data; public: friend std::istream &amp;operator&gt;&gt;(std::istream &amp;is, sentence &amp;s) { std::string temp, word; while (is &gt;&gt; word) { temp += word + ' '; if (word.back() == '.') break; } s.data = temp; return is; } operator std::string() const { return data; } }; int main() { std::copy(std::istream_iterator&lt;sentence&gt;(std::cin), std::istream_iterator&lt;sentence&gt;(), std::ostream_iterator&lt;std::string&gt;(std::cout, "\n")); } </code></pre> <p>Although somewhat longer and more complex, at least to me it still seems (considerably) simpler than the code in the question. I guess it's different in one way--it detects the end of the input by...detecting the end of the input, rather than depending on the input to contain a special delimiter to mark the end of the input. If you're running it interactively, you'll typically need to use a special key combination to signal the end of input (e.g., <kbd>Ctrl</kbd>+<kbd>D</kbd> on Linux/Unix, or <kbd>F6</kbd> on Windows).</p> <p>In any case, it's probably worth considering a fundamental difference between this code and the code in the question: this defines a sentence as a <em>type</em>, where the original code just leaves everything as strings, and manipulates strings. This defines an <code>operator&gt;&gt;</code> for a sentence, that reads a sentence from a stream as we want it read. This gives us a type we can manipulate as an object. Since it's like a string in other ways, we provide a conversion to string so once you're done reading one from a stream, you can just treat it as a string. Having done that, we can (for example) use a standard algorithm to read sentences from standard input, and write them to standard output, with a new-line after each to separate them.</p>