title: reading bytes with ifstream
body: <p>I'm relatively new to c++, and have some issues with ifstream. All I want to do is to read the file byte by byte, however, reading always fails in the middle of the file. My code:</p>
  
  <pre><code>void read(ifstream&amp;f)
  {
      unsigned char b;
      for (int i=0;;++i)
      {
          if(!f.good())
          {
              cout&lt;&lt;endl&lt;&lt;"error at: "&lt;&lt;i;
              return;
          }
          f&gt;&gt;b; // b=f.get(); and f.read(&amp;b, 1); doesnt work either
          cout&lt;&lt;b;
          /* ... */
      }
  }
  </code></pre>
  
  <p>It reads the first few hundred bytes correctly, then the rest of the file is skipped. Something wrong about buffering? What did I do wrong?</p>
  
  <p>EDIT:</p>
  
  <p>I just found out something that might be the cause: in the file I use CRLF line endings (2 bytes), but all the above methods return only LF, so at the end of each line i is incresed only by one, however there are 2 bytes in the file. So my question is: how can I obtain both CR and LF separately?</p>