Reading Binary Files in c++
Posted: Sun Jun 15, 2003 3:24 pm
Hi,
I have grasped all the basic stuff in C++. Variables, functions, classes, struvts, etc. Now I am trying to learn how to read binary files in c++ but I just can't seem to get it right.
I know how to open the file in binary mode, that's not the problem. The problem is how I should print the data to screen. If I read with fread and put them in an int I have more or less screwed up everything, right? Is there a way to output a single byte so I can see if my fread is accurate?
i.e
fread(buffer, 10, 1, file) // This reads 10 bytes into the buffer from file
but I have no other option than to use int as a buffer, so if I print what's in buffer[1] I get a huge INT, is that my binary number (which needs translation) or am I doing something fundamentally wrong?
Sorry if I seem confused, this is my first steps outside the first level of c++ programming ..
I have grasped all the basic stuff in C++. Variables, functions, classes, struvts, etc. Now I am trying to learn how to read binary files in c++ but I just can't seem to get it right.
I know how to open the file in binary mode, that's not the problem. The problem is how I should print the data to screen. If I read with fread and put them in an int I have more or less screwed up everything, right? Is there a way to output a single byte so I can see if my fread is accurate?
i.e
fread(buffer, 10, 1, file) // This reads 10 bytes into the buffer from file
but I have no other option than to use int as a buffer, so if I print what's in buffer[1] I get a huge INT, is that my binary number (which needs translation) or am I doing something fundamentally wrong?
Sorry if I seem confused, this is my first steps outside the first level of c++ programming ..