Which file type should I use to store game data

Started by
3 comments, last by JoeJ 1 year, 7 months ago

I want to know what is the best way to store game data in c++. For example I want to write clicker game and store in file amount of money and bought upgrades. And I think that using .txt file is kinda unprofessional. Or it is not. Idk so I am here.

Advertisement

.dat, .sav, no extension, any format you like, tbh. Unless maybe you have a clear specification?

Binary format is best. Use ofstream write() function to save to disk.

https://stackoverflow.com/questions/49492259/writing-binary-data-to-fstream-in-c/49492309#49492309

lorli said:
And I think that using .txt file is kinda unprofessional. Or it is not. Idk so I am here.

Only issue is that gamers can easily edit the file to cheat. If that's a problem, binary format is better.

In general, binary formats save disk space, are faster to load and save, and less work to implement. The larger the game, the more likely you want it.
But the downside is it's harder to maintain. If you save some structure of data as is from ram, but then you change the definition of your data structure in your source code, you can no longer load the outdated data.
Binary data also preserves numbers bit by bit, while a text based format may introduce rounding issues to floating point numbers.

Using text files is not unprofessional if it works for your needs.
But it would be unprofessional to spend lots of work on it, and only after that figuring out the rounding issues force you to use something else, for example.

This topic is closed to new replies.

Advertisement