我正在尝试从文本文件中删除特定单词,然后将剩余值重写到新文件中。我相信错误来自这里的代码:
string removeWord(string r){
ifstream wordBase("WordDatabase.txt");
ofstream temp("temp.txt");
string line = "";
while(getline(wordBase,line))
{
if(line != r)
temp << line << endl;
}
temp.close();
wordBase.close();
remove("WordDatabase.txt");
rename("temp.txt","WordDatabase.txt");
}
有人可以帮我吗?高度赞赏!