Re: Save/load functions not working
If you just need a few simple values...
An ini-file could be used
More complex, there's XML and a variety of XML libraties (msxml being installed by default on any WinXP and up).
a database is an option, as well (embedded such as SQLite or external), but for just a simple savegame this seems overkill. I wouldn't consider a database solution unless you were tracking scores/games for dozens/hundres/thousands of players.
the disadvantage to the above is that they're all going to have portability issues.
You can roll your own as well of course, but then you need to do things the right way, and not make wrong assumptions as to how things work. C++ streams are not the most ideal solution for this sort of thing.
Re: Save/load functions not working
Quote:
Originally Posted by
KruSuPhy
Also, as for the name with spaces problem I'm having, I attempted to use getline() for the input, but it didn't work. It would just go crazy and send into an infinite loop for some reason..
If you post the code giving you the problem, we'll be able to advise.
Re: Save/load functions not working
Quote:
Originally Posted by OReubens
a database is an option, as well (embedded such as SQLite or external), but for just a simple savegame this seems overkill. I wouldn't consider a database solution unless you were tracking scores/games for dozens/hundres/thousands of players.
At the moment, it looks like KruSuPhy is only experimenting with saving a single character, which is pretty much just a group of key/value pairs (and the keys may even be implied by the value position), so I agree. On the other hand, if more game state will eventually be saved, even if it is just for one player, a low overhead embedded database engine like SQLite makes for an excellent alternative to coming with one's own file format and implementing it, assuming that making the file format human readable is not a concern. SQLite was effectively designed to replace fopen (or in this case std::fstream) for such situations.
Re: Save/load functions not working
Well even in that case. I wouldn't consider a "database" unless I actually had... a database to store. as in multiple records with a similar layout. Otherwise you're adding a considerable amount of bulk (and code) to support a database to only have 1 record.
If the amount of data is limited, and if there is no compelling reason to go for a binary format (which there rarely is). I would opt for one of the simple parsed-text formats. such as
ini - extremely simple and supported by Windows API
xml - harder to get to know and get working, but the knowledge will serve you for other projects. It has widespread support, and an XML library (msxml) is installed with Windows. If you need portability there are portable libs that run on other OSes.
yaml
lua data
json
you can roll your own parsed format but then you also need to write a parser of your own. ANd it won't have external support.