How does one create their own file format in c++? I'm going to store some rather complex data for a game I am writing, and the .txt or .dat format is to convoluted and not exatly what I'm looking for.
How does one create their own file format in c++? I'm going to store some rather complex data for a game I am writing, and the .txt or .dat format is to convoluted and not exatly what I'm looking for.
“Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. " -John Carmack
File formats are literally whatever you want them to be. C allows you to have byte for byte control of a file, so you design your file format around your requirements. As long as you write the code to both write and read the contents of the file, it's up to you how it's stored.
It's a good idea to know the file manipulation routines very well if you want to get the most out of designing your own format.
There are some C/C++ techniques which are used a lot in the reading and writing of files, but I'll leave that to someone else, since I don't know a huge amount on that.
C/C++ Support IRC Channel
Server: irc.dal.net Channel: #csupport
Come along and help make it a great resource for the community.
Technically all files look the same. It's the file loader that decides how to decipher what's in it. As an example, Notepad uses the ASCII table to decipher txt files.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Take a look at some of the .ini files on your computer (I'm assuming Windows). A format like that is probably the simplest, if it will work in your application.
If you want to look at some more complex file-format specifications, check-out wotsit.org. Of these standard formats, the simplest that I know anything about are .wav, and .bmp.
As far as I know, there isn't one .dat standard. Lots of programs use the .dat file extension to save data in their own proprietary formats.
Even INI files requires minor token parsing, like [ and ].
If you want simplicity, use something like this:
...or something. All you do is some iterative file reading/writing with an std::string.Code:Enemy Name Goblin Health 100 Mana 0 Enemy Name Flying_Bird Health 80 Mana 200
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.