title: C++ - why cin.eof() read last char twice?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong">Why is iostream::eof inside a loop condition considered wrong?</a>  </p>
  </blockquote>
  
  
  
  <p><br/>
  I've got very simple question...
  </p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  int main()
  {
      char x;
      while(!cin.eof())
      {
          cin&gt;&gt;x;
          cout&lt;&lt;"char: "&lt;&lt; x &lt;&lt; endl;
      }
      return 0;
  }
  </code></pre>
  
  <p><br />
  Why when i try to run this code on Linux:<br />
  ./file_name &lt; test_file.txt<br />
  The result is:<br />
  char: a<br />
  char: b<br />
  char: c<br />
  char: d<br />
  char: d<br />
  when test_file.txt is only:<br />
  abcd<br /></p>