-
October 23rd, 2013, 09:13 AM
#31
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.
-
October 23rd, 2013, 09:42 AM
#32
Re: Save/load functions not working
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
October 23rd, 2013, 12:31 PM
#33
Re: Save/load functions not working
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.
-
October 24th, 2013, 06:56 AM
#34
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|