title: eof (end of file) function inside while loop in C++
body: <p>I'm reading a book "Guide to Scientific Computing in C++" and there is a code inside the book that doesn't run as supposed to do. </p>
  
  <p>Here is the listing from the book as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cassert&gt;
  using namespace std;
  
  int main()
  {
  int x[6], y[6];
  ifstream read_file("Output.dat");
  assert(read_file.is_open());
  
  int i = 0;
  while (!read_file.eof())
  {
  
      read_file &gt;&gt; x[i] &gt;&gt; y[i];
      cout &lt;&lt;x[i]&lt;&lt;" "&lt;&lt; y[i]&lt;&lt;"\n";
      i++;
  
  }
  read_file.close();
  return 0;
  }
  </code></pre>
  
  <p>Here is my "output.dat":</p>
  
  <pre><code>0 0
  1 0
  0 1
  0 0
  1 0
  0 1
  </code></pre>
  
  <p>When I run the program, I get :</p>
  
  <pre><code>0 0
  1 0
  0 1
  0 0
  1 0
  0 1
  4195984 807
  </code></pre>
  
  <p>So I wonder why it outputs  the trash data in the last line which is not in my data file. </p>