Hello everyone!
I am writing a high-score sub-routine for a text-based game. Here's what I have so far.
void Game::loadHiScores(string filename)
{
fstream hiscores(filename.c_str()); // what flags are needed?
int score;
string name;
Score temp;
if (hiscores.is_open())
{
for (size_t i = 0; i < TOTAL_HISCORES && !(hiscores.eof()); ++i)
{
cin >> score >> name;
temp.addPoints(score);
temp.scoreSetName(name);
hiScores.push_back(temp);
}
}
else
{
//what should go here?
}
hiscores.close();
}
How can I make it so that:
IF the file exists, it shall be open for reading
ELSE the file shall be created
Thanks for your time