我正在为基于文本的游戏编写高分子程序。这是我到目前为止所拥有的。
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();
}
我怎样才能做到这一点:
如果文件存在,则应打开以供阅读
否则应创建文件
谢谢你的时间