title: C++ reading a file in binary mode. Problems with END OF FILE
body: <p>I am learning C++and I have to read a file in binary mode. Here's how I do it (following the C++ reference):</p>
  
  <pre><code>unsigned values[255];
  unsigned total;
  ifstream in ("test.txt", ifstream::binary);
  
  while(in.good()){
      unsigned val = in.get();
      if(in.good()){
          values[val]++;
          total++;
          cout &lt;&lt; val &lt;&lt;endl;
      }
  }
  
  in.close();
  </code></pre>
  
  <p>So, I am reading the file byte per byte till <code>in.good()</code> is true. I put some <code>cout</code> at the end of the <code>while</code> in order to understand what's happening, and here is the output:</p>
  
  <pre><code>marco@iceland:~/workspace/huffman$ ./main 
  97
  97
  97
  97
  10
  98
  98
  10
  99
  99
  99
  99
  10
  100
  100
  10
  101
  101
  10
  221497852
  marco@iceland:~/workspace/huffman$
  </code></pre>
  
  <p>Now, the input file "test.txt" is just:</p>
  
  <pre><code>aaaa
  bb
  cccc
  dd
  ee
  </code></pre>
  
  <p>So everything works perfectly till the end, where there's that 221497852. I guess it's something about the end of file, but I can't figure the problem out.</p>
  
  <p>I am using gedit &amp; g++ on a debian machine(64bit).
  Any help help will be appreciated.</p>
  
  <p>Many thanks,</p>
  
  <p>Marco</p>