CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 34 of 34
  1. #31
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  2. #32
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Save/load functions not working

    Quote Originally Posted by KruSuPhy View Post
    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)

  3. #33
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  4. #34
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured