I am making a game, the game works, but when I exit the console application, I want the game to save the user's progress, such as money and items they have bought. I am not sure how to, I am new to c++. Thanks for taking your time to read this.
            Asked
            
        
        
            Active
            
        
            Viewed 367 times
        
    -1
            
            
        - 
                    You save it in a file in an easily readable format, and read it back when you start the next time. – molbdnilo Aug 18 '21 at 07:36
- 
                    Ok, how do I do that. Sorry im new – cool bean Aug 18 '21 at 07:36
- 
                    3The best start is to get a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and read about files. – molbdnilo Aug 18 '21 at 07:37
- 
                    i have edited my questions. does that code work? – cool bean Aug 18 '21 at 07:45
- 
                    What is `FileInput`? Is it a class that you made, or just your guess at how input/output could've worker? – HolyBlackCat Aug 18 '21 at 07:47
- 
                    To be honest I have copied that code, from another forum with a similar question and tried to adapt that code to my game. But I do not understand it. – cool bean Aug 18 '21 at 07:48
- 
                    you have to make up your mind what you want to write to the file and in which format, most of this is not specific to C++. Once you know what you want in the file you can turn to implementing it in C++ – 463035818_is_not_an_ai Aug 18 '21 at 08:07
- 
                    How do i do that in code? – cool bean Aug 18 '21 at 08:10
- 
                    just google: how to read file in c++ and how to write file in c++. That's it. – Yves Aug 18 '21 at 09:17
1 Answers
2
            
            
        To save progression you need to create a saveFile, you have to define what variables to save (money, items, current life, posX, posY,...).
You can define any readable file format like JSON :
{
     "player":{
         "life":26,
         "max_life":40,
         "bag":{
             "max_number_items":15
             "items":[..,..,..]
}
Or anything else like this:
<PLAYER>
max_life=40
life=26
</PLAYER>
<BAG>
max_number_items
..
</BAG>
And then on load, you have to read your file to get back your data
 
    
    
        Chiquito_Sensei
        
- 65
- 5
