[Making My Game] Save and Load

Hello guys, its my first topic here because im trying a new thing in my c++ knowledge.

Im making a console game and i wanna make 2 things:

- Make a random number to make the game different every the game loads.

- Make a Save and Load System.


If you guys can help me please reply =D


PS: Im using Dev C++.
i only use Dev C++ because i learn the basics in dev cpp.. now idk how to program on vc++...

You don't need to use VisualStudio...
Look up code::blocks =)
You can learn the basics just fine with an up-to-date IDE such as Code::Blocks, which comes with a recent version of MinGW.
http://www.codeblocks.org/downloads/26
After installing the above, you might want to update for improved code completion:
http://forums.codeblocks.org/index.php?topic=14206.0

Don't forget to remove Dev-C++ tracelessly from your system before you install Code::Blocks.
If you don't, Code::Blocks might try to use the ancient version of MinGW that comes with Dev-C++.
Ok let's talk about save and load. A simple approach is to put your entire game's data into one struct, which you can then write into a file.
thanks for the replys

@ rocketboy9000

i want to do that but idk how to read each data then..

example:

Save.txt:

username
password
name2
name3
blablabla
blablabla2

Then if the program just want the name2 how can i lead it to the 3rd line?
you have to read the other lines and ignore them.
Alternately write the data out in binary form.
Last edited on
thanks but im thinking in a new way, its more dificult but its easier to understand:

i will make a .txt file for each line of info and data.

then i will use cmd and type this: "attrib *.txt -s -h"

This will hide the files and then i just add some blank files and its rdy! xD


then i will use cmd and type this: "attrib *.txt -s -h"


That would get the job done but stay away from system(); anything...
hum nice idea, in the beggining of the program i will put:

system("attrib Data\*.txt -s -h");

thanks ;)
Er, you are making a mistake there.

There is no valid reason to hide the user's saved game status. Just write it to a normal file. If you are concerned about discouraging the user from playing with his status in the game, write the file in binary, or encode it with a two-way function.

If you must make it a hidden file, use the Windows API to do it, instead of using system().


And all you giving him grief about his choice of IDE instead of helping answer his questions... shame.
I agree with Duoas, it would look something like this:
SetFileAttributes(PointerToFileName, FILE_ATTRIBUTE_HIDDEN);
That was easy wasn't it? You can find the documentation here:
http://msdn.microsoft.com/en-us/library/aa365535(VS.85).aspx

EDIT: I had a paragraph in here showing how to use the "EncryptFile(...)" function, forgetting that it means something completly different from what you are talking about.
Last edited on
closed account (3hM2Nwbp)
The Property Tree library from Boost would also be a viable choice. You can parse INI, JSON, and XML with it.

http://www.boost.org/doc/libs/1_45_0/doc/html/property_tree.html
Topic archived. No new replies allowed.