C++: cin.peek(), cin >> char, cin.get(char)
<p>I've got this code with use of cin.peek() method. I noticed strange behaviour, when input to program looks like "qwertyu$[Enter]" everything works fine, but when it looks like that:
"qwerty[Enter]$" It works only when I type double dollar sign ("qwerty[Enter]$$") . On the other hand when I use cin.get(char) everything works also fine.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cstdlib&gt;

using namespace std;



int main()
{
char ch;
int count = 0;

while ( cin.peek() != '$' )
{
    cin &gt;&gt; ch;         //cin.get(ch);
    count++;
}

cout &lt;&lt;  count &lt;&lt; " liter(a/y)\n";

system("pause");
return 0;
}


//Input:
// qwerty$&lt;Enter&gt;  It's ok
//////////////////////////
//qwerty&lt;Enter&gt;
//$                Doesn't work
/////////////////////////////
//qwerty&lt;Enter&gt;
//$$                 works(?)
</code></pre>
