title: Clear cin in C++
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/478258/why-is-this-cin-reading-jammed">Why is this cin reading jammed?</a>  </p>
  </blockquote>
  
  
  
  <p>I overloaded the istream operator (<code>istream &amp;operator&gt;&gt;...</code>) and it takes in a Point of the format:</p>
  
  <pre><code>(&lt;x-coordinate&gt;,&lt;y-coordinate&gt;)
  </code></pre>
  
  <p>I want to test this out multiple (10) times, and so have written:</p>
  
  <pre><code>for (int i = 0; i &lt; 10; i++)  {
      cin &gt;&gt; a;
      if (!cin.fail()) { cout &lt;&lt; a &lt;&lt; endl; }
      else { cout &lt;&lt; "Invalid input!" &lt;&lt; endl; cin.clear(); }
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I now have the following code:</p>
  
  <pre><code>for (int i = 0; i &lt; 10; i++)  {
      cin &gt;&gt; a;
      if (!cin.fail()) { cout &lt;&lt; a &lt;&lt; endl; }
      else {
          cout &lt;&lt; "Invalid input!" &lt;&lt; endl; cin.clear();
          while (!cin.eof()) { cin.ignore(); } cin.ignore();
      }
  }
  </code></pre>
  
  <p>The ignore was suggested by Cthulhu. However, the problem is cin still outputs "Invalid input!" after running through the code above:</p>
  
  <pre><code>(3,3) &lt;-- input
  (3,3) &lt;-- output
  Invalid output! &lt;-- second output
  </code></pre>
  
  <p>Is there a way that I can clear what is in cin?</p>