I'm starting a little text-based RPG project and need help with FileI/O. i can get the code to write the characters name to the file (WrathData.txt) but cannot get the program to read it from that file when i restart the application. please help.
the BOLD text is the problem area.
here's the code:
string charname;//getting character's name
string newgame;//new game y/n holder
string gamedata;//for file io
int x;//for file io
int main()
{
/*Main Intro Screen*/
cout << "================================== Wrath ==================================" << endl;
cout << endl;
cout << "Welcome to Wrath, the text based RPG game." << endl;
cout << endl;
cout << "================================== Wrath ==================================" << endl;
system("PAUSE");
system("cls");
/*Bottom of Intro Screen*/
/*New Game y/n*/
cout << "Are you starting a new game? (y/n)";
cin >> newgame;
/*New game Yes*/
if(newgame == "y"){
/*Get data from file*/
/*Get Character Name*/
cout << "What is your name? ";
cin >> charname;
system("cls");
cout << "Welcome " << charname <<", to the temple of The Gods\n";
Sleep(1000);
cout << "Prepare to feel the wrath!\n";
Sleep(2000);
system("cls");
/*End Get Character Name*/
/*Intro*/
cout << "So, " << charname <<",\n";
Sleep(1500);
cout << "you are a demigod, A god/human mix breed.\n";
Sleep(1500);
cout << "capable of utilizing marvelous powers.\n";
Sleep(1500);
cout << "but, before you can use these powers your father god must accept you\n";
Sleep(2000);
cout << "as his son...\n";
Sleep(3000);
system("cls");
/*End Intro*/
Anyway why are you using a char array to save the player name? Why not just save it as a string:
1 2 3 4 5 6 7 8 9 10
string charname;
// when saving
ofstream file("whatever");
file << charname << '\n'; // put a new line after the name
// when loading
ifstream file("whatever");
getline(file,charname);