How can I include '\n' into the while (cin >> x) idiom?
<p>My understanding is that the operator <code>&gt;&gt;</code> returns the left operand, so <code>cin &gt;&gt; x</code> returns <code>cin</code> which has a value of <code>false</code> if we encounter an <code>EOF</code> or other errors. Now my guess is that since <code>cin</code> skips whitespace, characters like <code>\n</code> don't get stored. What I'd like to do is something like this:</p>

<pre><code>int x;

while((cin &gt;&gt; x) and x != '\n')
    // do stuff
</code></pre>

<p>So that when <code>cin</code> encounters a newline in the stream, it exits the input loop (as it would normally do with say, <code>EOF</code>).</p>
