I am working on a game, and I was just kinda wondering how one would go about making save files and whatnot. I've looked on google many times, but each time, I just ended up getting confused O_o can anyone help?
You need to persist to disk all the variables that are required to resume the game where the player left. That's the most accurate answer I can give you without knowing anything else.
#include <fstream> / / Lets you the capability to work with files
int main(){
ofstream file1("fileName.ext");
// Can use anything in place of "file1" , "fileName.ext"
// fileName.ext is the file that is saved on disk
file1 << "txt";
file1 << variable;
file1.close();
return 0;
}
you can read more for how to open a file and read out of it.
file1 is the name of variable file, just like you declare
int x = 1;
now you use x in the program to do some thing with it, similarly you refer file1, you can chose to call it any thing myFile, savedFile or any thing
Second is "fileName.ext", similarly its the actual name of file which exist on the disk, you can also use any name or any extension for it but the thing to note is that it will be a text file, so if you skip the ".ext" part than it will be shown as a non Associated file, If you use ".txt" (which you should) then you can open it in notepad by double clicking.
You should also save as binary, not as text. Saving as text poses several issues, like date formats and number formats which make the savegame file non-portable among PC's configured differently.
it says variable is an undeclared identifier, but Im assuming, that i need to put something else there? if so what is it, and what does it do? sorry if i sound like a complete noob, my mind just doesnt want to comprehend fstream for some reason Dx
For that you need to read a reference (tutorial if never used before, as in your case) for fstream.
There are many things involved for reading back that file:-
Open it
read from it
convert the data (data in txt file is stored as strings)
reassign it to variables in your program