Original Post
Im in the middle of writing some code that can handle saving stuff to a binary file.
On the lowest level, im writing simple data types using the write method of the fstream object.
I do it like this
file is a fstream* opened in binary mode, val is what we are saving)
file->write((char*)&val,sizeof(val));
This works fine, but im not 100% sure the result is correct.
For example if i write an int, the result is 4-bytes of data as it should be. But lets say i write an integer with value 1, viewing this with a binary file viewer shows this:
00000001 00000000 00000000 00000000
I was kind of expecting something like:
00000000 00000000 00000000 00000001
If the int increases in size to for example 256(ie moving into the next byte) i get this:
00000000 00000001 00000000 00000000
Where i was expecting:
00000000 00000000 00000001 00000000
Am i being stupid or something?
[edited by - ziphnor on June 11, 2002 4:49:18 PM]