title: file handling in c++
body: <p>I wrote the following code to input numbers from a file however the last number gets printed twice which I find perplexing. What could be the possible answer.
  Thanks in advance.</p>
  
  <p>code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  using namespace std;
  int main()
  {
      int x;
      ifstream f;
      f.open("note");
      while(!f.eof()){
              f&gt;&gt;x;
              cout&lt;&lt;x&lt;&lt;endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>gives output:</p>
  
  <pre><code>1
  2
  3
  4
  5
  5
  </code></pre>
  
  <p>the contents of file note are:</p>
  
  <pre><code>1
  2
  3
  4
  5 
  </code></pre>