//includes
//some variables and strings not related to the problem:
float score = 0;
string Name; //User Name for File input;
string prev_score; //Previous User's Score;
ofstream user_score ("Score.txt");
ifstream prev_user("Score.txt");
//Structs, Functions and the main function, that contains calls to these functions.
//Deriving data from file:
while( prev_user.good() )
{
getline (prev_user, prev_score);
cout << prev_score << endl;
}
prev_user.close();
//Inputting Data to file:
user_score << "The previous player was: " << Name << endl;
user_score << Name << " scored " << score << " points.";
user_score.close();
//Termination.......
So when I run the proggram, I don't get data from the file (tested it for ten consecutive times).
I did the third suggestion.
It opens the file for reading, then it should take in the data stored in the file and present it to the user. Then close the file then open it for changing the text. Then update the info in the file.
I looked for the file and found out that it was empty. So I imagine that the problem is in inputing the data into the file.
Your code is not doing the 3rd option as you're using two distict streams within your app that don't know about each other. You'd be required to open the file once, which changes your read/write code.