title: End of File in C++
body: <p>I have a n X 2 matrix stored in a text file as it is. I try to read it in C++</p>
  
  <pre><code>nb_try=0;
  fin&gt;&gt;c_tmp&gt;&gt;gamma_tmp;
  while (!fin.eof( ))      //if not at end of file, continue reading numbers
  {
    // store
    cs_bit.push_back(c_tmp);
    gammas_bit.push_back(gamma_tmp);
    nb_try++;
  
    // read
    fin&gt;&gt;c_tmp;
    assert(!fin.fail( )); // fail at the nb_try=n   
    if(fin.eof( ))break;
    fin&gt;&gt;gamma_tmp; // get first number from the file (priming the input statement)
    assert(!fin.fail( ));    
  
  }
  </code></pre>
  
  <p>The first assert failes, i.e. fin.fail( ) is true, when nb_try==n, which happens when it tries to read the first number which does not exist. But how come fin.eof( ) is not true after reading the last number? Does it mean it becomes true only when reading the first number that does ot exist? Also is it true that fin.fail( ) and fin.eof( ) are becoming true at the same time?</p>
  
  <p>Thanks and regards!</p>