How can I read multiple bytes from a file at a time?
<p>I want to read 8byte chunks from a binary file at a time till I reach end of the file. Why doesn't this code work? What are the alternatives?</p>

<pre><code>// read a file into memory
#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;

int main () {

  long long int * buffer;

  ifstream is;
  is.open ("test.txt", ios::binary );

  // allocate memory:
  buffer = new long long int;

  // read data:
  while(!is.eof())
      is.read (buffer,sizeof(long long int));
  is.close();


  delete[] buffer;
  return 0;
}
</code></pre>

<p>If I replace all <code>long long int</code> with <code>char</code>, the code works perfectly.</p>

<p>Ref: code adapted from <a href="http://www.cplusplus.com/reference/iostream/istream/read/" rel="nofollow">www.cplusplus.com</a></p>
