I'm having a slight problem. This particular function is crashing caused by the Loadfile ifstream being opened.
void LoadChar(Entity players[], char saveNum)
{
string filename, saves;
saves = saveNum;
filename = "save/Save" + saves + ".sav";
char *file;
file = const_cast<char*>(filename.c_str());
ifstream Loadfile(file, ios::in); //this little diddy right here
if (!Loadfile)
{
cout<<"Error saving player data!"<< endl;
return;
}
if ( Loadfile.is_open() )
{
try
{
Loadfile >> players[0].name;
Loadfile >> players[0].health;
Loadfile >> players[0].strength;
Loadfile >> players[0].inRoom ;
Loadfile.getline(players[0].descrip, 56);
Loadfile >> players[0].isNPC;
Loadfile >> players[0].hasScript;
}
catch (exception&)
{
cerr<<"Something went horribly wrong!"<< endl;
}
}
Loadfile.close();
}
I surrounded the problem line with a try/catch block and it catches as a st9exception which is about as useful as telling me something went wrong.
Anyone have any ideas on why this is happening, I had the same problem with the SaveChar function and I completely forgot how I fixed it.