Hopefully this is a simple question to answer. I can't seem to find anything via searches, but perhaps I do not know exactly what to look for.
I am reading a file, in hex, and converting the values as I go.
For instance a file might have (in hex):
2345 6789 0000 0004 0000 0001 0000 0001 0000 0008 0000 000C
0100 0000 ... and so forth.
Now in a hex editor I can view this just fine, but as I interpret it with my own program, interesting things start to happen.
I read byte by byte through the file using std::iostream.
Then I make sure the file is open:
in.open( "thefile", ios::binary );
I realize this is not the best way of reading it, but it worked for me for a while, and now I hit a wall.
char *temp = new char;
if( in.is_open() )
//read 4 bytes then analyze
in.read( temp, 4 );
//convert to hex
hex.Format( "%X%X%X%X", temp, temp, temp, temp );
//do whatever I wish with it, and move on
Say when reading the line I listed above, 2345 6789 ...
I can read 2345 6789 fine, but when I hit 0000 0004, it chops the first 0000 off when I read the value, and when I format. Then when I hit the second line, instead of getting the value of 0100 0000, I get 1000, which makes no sense. Perhaps I am just not quite understanding what I am doing here, but any pointers would be helpful. Thanks!