【发布时间】:2010-05-14 13:44:01
【问题描述】:
我正在为基于文本的游戏编写高分子程序。这是我目前所拥有的。
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();
}
我怎样才能做到:
如果文件存在,则应打开以供阅读
否则将创建文件
感谢您的宝贵时间
【问题讨论】:
标签: c++ text text-files fstream