Hi everyone!,
I have this code to overwrite the high score in the highscore.txt file
in a RPG game that I'm working on for class. I keep getting a 'outfile
undeclared' fist use this function when it gets to the bolded open file
for output part. I included #include<fstream> at the beginning. Any
idea's??
Also, I tried putting curley brakets around after the if statement since
it's a compound statement block, but then I get this error from dev c++
empty character constant
thx!
//Write player's high score if greater then score in txt file
//declare file pointer for input
ifstream infile;
//declare variables
string fileName = "";
int highScore = 0;
//Open file for input
infile.open("highscore.txt", ios::in);
//read in data
getline(infile, fileName);
infile>>highScore;
//Close file
infile.close();
if (playerScore > highScore)
//declare file pointer for input
ofstream outfile;
*//Open file for output
outfile.open("highscore.txt", ios::out);*
//write data
outfile<<playerName<<playerScore<<endl;
//close file
outfile.close();
|