For some reason i cant output to a file unless it was already created.
Here's my code.
fstream myfile;
myfile.open (filename.c_str(), ios_base::in);
if (!myfile)
{
myfile.close();
myfile.open (filename.c_str(), ios::out);
avatar.name = name;
avatar.init();
myfile << "Name = " << avatar.name << endl;
myfile << "hp = " << avatar.hp << endl;
myfile << "mana = " << avatar.mana << endl;
myfile << "level = " << avatar.level << endl;
myfile << "strength = " << avatar.strength << endl;
myfile << "intelligence = " << avatar.intelligence << endl;
myfile << "wisdom = " << avatar.wisdom << endl;
myfile << "dexterity = " << avatar.dexterity << endl;
myfile << "charisma = " << avatar.charisma << endl;
myfile.close();
}
else
{
cout << name << " already exists" << endl;
}
Now i create the file and output the data into it, but it wont work unless i have the file already created and open it.