Adapting some of the code I have seen in SO, I came out with the following solution:
fstream file("sample.bin", ios::binary | ios::in | ios::ate);
unsigned char charsRead[(int)file.tellg()];
file.read((char *) &charsRead, sizeof(char*));
for(int i=0; i<sizeof(charsRead); i++)
cout << (int) charsRead[i] << endl;
file.close();
It does compile, but every time is executed, it returns a different output. Does anyone know why this is happening?
sizeof(char*)does what you think it does?unsigned char charsRead[(int)file.tellg()];is a non standard VLA. If you need to read into acharbuffer consider astd::vector<unsigned char>.