title: C++ : how to read to separate variables and then to vector?
body: <p>Having this:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;istream&gt;
  
  using namespace std;
  
  void read_vector(istream &amp;in, vector&lt;double&gt; &amp;vec)
  {
      if (in) //check wheter !in.fail() =&gt; but how can &quot;cin&quot; have error status??
      {
          vec.clear(); //also, clear the vector (general function)
          double tmp;
          while (in &gt;&gt; tmp)
          {
              vec.push_back(tmp);
          }
          in.clear(); //should be there any error?
      }
  }
  
  int main()
  {
      double a, b;
      vector&lt;double&gt; vec;
      while (cin &gt;&gt; a &gt;&gt; b)
          ;
      read_vector(cin, vec);
  
      for (int i = 0; i &lt; vec.size(); i++)
      {
          cout &lt;&lt; vec[i] &lt;&lt; ' ';
      }
      cout &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  <p>I compile and try to give test values:</p>
  <pre><code>$./a.out 
  $1.2 3.4 5.6 7.8
  $
  </code></pre>
  <p>NO output. the <code>1.2</code> should be saved to variable <code>a</code>, the <code>3.4</code> should be saved to variable <code>b</code>, and the rest stored to vector (via function <code>read_vector</code>). I think since it is in <code>while()</code> the bool condition of istream is still true.</p>
  <ol>
  <li><p>What are condition to make istream false (I know of wrong value, EOF, or other signal).</p>
  </li>
  <li><p>Please give some practical example of <code>good()</code>, <code>fail()</code>, <code>bad()</code>, <code>operator bool</code> and <code>operator!</code> -&gt; according to <a href="https://en.cppreference.com/w/cpp/io/basic_ios/operator_bool" rel="nofollow noreferrer">https://en.cppreference.com/w/cpp/io/basic_ios/operator_bool</a></p>
  </li>
  <li><p>But there could be no &quot;wrong&quot; value (or other then type <code>double</code>) - how will the <code>cin</code> recognize to stop input to operands (<code>a</code>,<code>b</code>), make the <code>cin</code> wrong, and then continue to next function <code>read_vector</code> (so it eventually will populate the vector and I could see the result from the for loop)</p>
  </li>
  </ol>