Hey ! I'm pretty new to C++, and I want to make a RPG game and I want to implement a save / load option, I searched it on Google, but I didn't undersand anything ...
There is no general solution for this. It depends on the way your program is structured, what data you have...
If you do a search for "rpg c++" should give you plenty of examples.
Sorry for my bad exprimation, I was meaning <fstream>. I would show you the code, but is long(700+), couldn't you show me an example of <fstream>(that's the best way I can learn something) ?
I still don't understand.
You need to include the header file with #include <fstream>
That give you access to the ifstream, ofstream and fstream classes.
What you do with them depends on the data you need to save and load.
To read data from a file you use
1 2 3 4 5 6 7
ifstream input("filename");
if (!input)
{
// handle error
return -1;
}
// code to read the data
To write data to a file you use
1 2 3 4 5 6 7
ofstream output("filename");
if (!output)
{
// handle error
return -1;
}
// code to write the data
I did it ! I made a .txt for every variable, it was long , but it worked. THANKS !
Mind if I ask you a question ? How to delete the .txt files ? (if the Player wants to start a new game)
Sorry for the trouble.
the remove(filename) function will delete it if it can be deleted (not currently open, permissions, etc must be in a state that your program is allowed to do it). Its in <cstdio>. Not sure if there is a newer approach or not.
Your operating system libraries probably also have a tool to do this, I know windows visual c++ has a file delete in their calls. I always did it that way...