//This is the region that defines the function for saving
#pragma region Save Game
void saveGame()
{
ofstream mySaveFile;
mySaveFile.open("save.txt", ios::out | ios::app | ios::binary);
while (mySaveFile.good())
{
mySaveFile.open("save.txt");
mySaveFile<<"Here are the items:"<<endl;
mySaveFile<<item1;
mySaveFile<<item2;
mySaveFile<<item3;
mySaveFile<<item4;
mySaveFile<<item5;
mySaveFile<<"Here are the rooms/levels:"<<endl;
mySaveFile<<level;
mySaveFile<<room;
mySaveFile<<"Here's the character's name:"<<endl;
mySaveFile<<characterName;
mySaveFile<<flush;
}
}
#pragma endregion
is there ANYTHING wrong in the code? if so, please tell me
1) You are opening the save file on line 6. So why are you opening it again on line 8? It's already open.
2) Your loop on line 7 is pointless. That will just deadlock your program unless the file fails to open because it will keep looping.
3) You need to be able to read back the data you write, which means you'll need to have some kind of division that you can identify. As it stands now you're writing a file that might look like this:
item1item2item3item4item5levelroom
Notice how all the names are mushed together. How do you expect to separate them when you load this file?
Assuming all these strings are 1 line each... you can separate them by putting a new line between them.
4) There's not much need to put human-readable descriptors in the file unless you're expecting the file to be human readable. ie: "Here are the items:" contributes nothing to this file. I would say get rid of it.