I've been working on an RPG on and off for a while, and I'd been having difficulties with saving and loading. I'd been using some odd procedure, but switched over to a standard 'fout', 'fin' system. I ran into trouble, though, because pieces of data such as "short sword" that contain more than one word that are assigned to one variable (in this case, Player1.weapon). I was using strings to store the variables, and when I went to load my game, instead of 'Player1.weapon="Short Sword"' the game would recognize the space as a break and set 'Player1.weapon="Short"' and 'Player1.armor="sword"'. The tutorial on saving and loading that I was using said that changing values to character arrays would make it so that I could tell the program to input the save values as a line instead of switching to the next value at the end of each word in the save file, so I switched all my strings out for char*. Saving functions exactly the same (I've checked my save files to ensure that the change in variable type wasn't changing the data storage) however when I go to load, it crashes before it even starts loading the first value. Here is some of the save code:
fout << Player1.name;
fout << "\n" << Player2.name;
fout << "\n" << Player3.name;
fout << "\n" << Player4.name;
fout << "\n" << Player1.exp;
fout << "\n" << Player2.exp;
fout << "\n" << Player3.exp;
fout << "\n" << Player4.exp;
etc.
and the start of the loading code:
void load()
{
cout << "enter the name of the file you wish to load.\n";
cin >> filename;
ifstream fin(filename);
//usually crashes somewhere around here
if (!fin)
{
cout << "that file doesn't exist.\n";
load();
}
else if (fin)
{
fin >> Player1.name;
fin >> Player2.name;
fin >> Player3.name;
fin >> Player4.name;
fin >> Player1.exp;
fin >> Player2.exp;
fin >> Player3.exp;
fin >> Player4.exp;
etc.
filename is a char[17]
Anyone have any advice on this?