cin buffer not being ignored?
<pre><code>while(cout &lt;&lt; "Enter a positive integer: " &amp;&amp;
        (!(cin &gt;&gt; anInteger) || anInteger &lt; 0))
{
    cout &lt;&lt; "Enter a positive integer.\n";
    cin.clear();
    cin.ignore(numeric_limits&lt;streamsize&gt;::max(), '\n');
}

while(cout &lt;&lt; "Read or write (r/w): " &amp;&amp;
        (!(cin &gt;&gt; rw) || (rw != 'r' &amp;&amp; rw != 'w')))
{
    cout &lt;&lt; "Enter r or w.\n";
    cin.clear();
    cin.ignore(numeric_limits&lt;streamsize&gt;::max(), '\n');
}
</code></pre>

<p>Here I ask for an integer, followed by 'r' or 'w'. However, when inputting something like '4r' into the first while statement, the 'r' stays in buffer and is applied to the next while statement.  How can I fix this?</p>

<p>What's the easiest way to only accept input if it's ALL integers in the first while loop instead of cutting off characters?</p>