Hey so i just learned about the i/o part of the STL, more specifically fstream. Although I can now save binary info and classes i've made to the hard drive, i am not sure how to define how the info should be read.

I saw the answer for making a file format from [this][1] post:

Typically you would define a lot of records/structures, such as BITMAPINFOHEADER, and specify in what order they should come, how they should be nestled, and you might need to write a lot of indicies and look-up tables. Such files consists of a number of records (maybe nestled), look-up tables, magic words (indicating structure begin, structures end, etc.) and strings in a custom-defined format.

What i want to know specifcally is how to do this with the STL and C++... Since the format is meant simply for the use of a game i would think it would be much easier though. The format should:

  • Be traversable (i can look through it and find the start of structure and maybe check it's name
  • Be able to hold multiple classes and data in a single file
  • have identifiable starts and ends to sections: such as the space in text files
  • Maybe have it's own icon to represent it??

How do i do this in c++ ?

  • 1
    \$\begingroup\$ gamedev.stackexchange.com/questions/4107/… \$\endgroup\$
    – Tetrad
    Commented Jul 23, 2011 at 0:11
  • 4
    \$\begingroup\$ Also I think asking how to make the file format is a bit of a misfire. The file format is whatever you write to disk. And if you know how you wrote it to disk, you can probably figure out how to read it back. The reason you would define the file format is so that people without your code could read the file, but you probably don't need to do that. \$\endgroup\$
    – Tetrad
    Commented Jul 23, 2011 at 0:13

1 Answer 1


try using boost serialize! other than that what you are asking for is how to implement serialization and that's a real complicated thing! I've recently implemented an implementation for serialization and it's no easy case to talk about.

there is also another way to only save one class into file which contains all the information you need, which makes saving/loading classes much more simpler.

by the way icon is not anything related to file format it's something OS generates per file, and usually icons are stored somewhere between OS files. except for windows executable files(as far as I know). windows executable files are like a zipped folder, containing the actual binary operations, icon data for some various resolutions, and maybe some other data related to OS itself.

  • \$\begingroup\$ -1, what he is after is not strictly serialization. +1 for mentioning icons are related to the O/S. \$\endgroup\$ Commented Jul 23, 2011 at 0:57
  • \$\begingroup\$ @danien: as far as I can tell from his question he is looking for some way to dump all his classes and then load them to exact same state after program restarts. that's serializing! note that he want to Be able to hold multiple classes and data in a single file. \$\endgroup\$
    – Ali1S232
    Commented Jul 23, 2011 at 4:54
  • 2
    \$\begingroup\$ It strikes me as a "basic programming" matter really: knowing how to convert (or serialize if you will) data into different formats or structures before writing them to a file or whatnot kind of stream. Chunks can be used to add hierarchy, other than that it's just a matter of experimentation I guess. No surefire answer to this. \$\endgroup\$
    – njdw
    Commented Jul 23, 2011 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .