title: istream reading after failure
body: <p>I have a small piece of code to read user data, like below:  </p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;vector&gt;
  #include&lt;algorithm&gt;
  #include&lt;ios&gt;
  #include&lt;iomanip&gt;
  #include&lt;string&gt;
  
  using namespace std;
  
  istream&amp; read_dt(istream&amp; in, vector&lt;int&gt;&amp; nmbr) {
  if(in) {
   nmbr.clear();
  
   int x;
    while(in &gt;&gt; x) {
     nmbr.push_back(x);
    }
    if(in.fail()) {
     string s;
     in &gt;&gt; s;
     in.clear();
    }
   }
   return in;
  }
  
  int main() {
   vector&lt;int&gt; data;
   cout &lt;&lt; "Enter all the data: " &lt;&lt; endl;
   read_dt(cin, data);
   cout &lt;&lt; "Size: " &lt;&lt; data.size() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>When I compile and execute this above program using the following data:
      1 2 3 4 r t 5 6 7</p>
  
  <p>I seem to get a vector of size 4 instead of size 7.  What I though, I implemented above is, that when a user gives invalid inputs  as data (in this case 'r' and 't'), that data is discarded and the input is cleared (using in.clear()), and the remaining inputs are "pushed" into the vector data.  </p>
  
  <p>But that does not seem to be happening.  What am I doing wrong? Can someone please help?</p>
  
  <p>Thanks.</p>