How to clear cin Buffer in c++
<p>I have gone through many existing answers here StackOverflow, but I am still stuck.</p>

<p>code:</p>

<pre><code>int c;
cin &gt;&gt; c;

if(cin.fail()) {
   cout &lt;&lt; "Wrong Input";
   cin.clear();
   cin.ignore(INT_MAX, '\n');
}
else
{
   cout &lt;&lt; c*2;   
}
</code></pre>

<p>If I enter wring input e.g <code>s</code> instead of an integer, it outputs <code>Wrong Input</code>. However, if I enter an integer, and then I enter a string, it ignores the string and keep outputting the previous integer result, hence it does not clears the cin buffer, and the old value of <code>c</code> keeps on executing.
Can anyone please suggest the best way other than <code>cin.ignore()</code> as it does not seem to work. 
and yeah for me, the max() in <code>cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');</code> gives error. So this does not work either.</p>