Alright , so I spent _forever_ trying to figure this out. So, if any newbies here need to know how to write and read ANY object (with the exclusion of pointers, but I'll get to that), this is something that can help.
First and foremost, you have to take endianness into account whenever you are working with binary data. We simply use a #define to explicitly state to write with big or little (1 being big, 0 being little).
The code should be fairly straightforward, and what is wonderful is you don't have to explicitly state what the types are thanks to templates. So the following code would work
You should be able to figure out writing pointers/arrays ;) If not, you're not ready to be saving them anyways :P
Also, you should try to roll your own functions after trying this out. I didn't know how to use Unions (hell I didn't even know what they were), and my pointer/dereference was a bit rusty. Also, it helped me learn how memory is mapped better.
This probably won't save complete class objects correctly, you might want to roll your own class function for saving and loading them. If you need to get a head start, I can post my class's functions for you, but you should try to figure it out on your own.
EDIT: Shoot, I forgot to put everything in a main function. Oh well, you should be able to fix that.
Edited 5 Years Ago by hondros: n/a