テキストベースのゲームのハイスコア サブルーチンを書いています。これが私がこれまでに持っているものです。
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();
}
次のようにするにはどうすればよいですか。
ファイルが存在する場合は、読み取り用に開かれます
それ以外の場合、ファイルが作成されます
御時間ありがとうございます