我是文件处理新手......
我正在编写一个程序,以下列格式保存文本文件中的数据:
3740541120991
Syed Waqas Ali
Rawalpindi
Lahore
12-12-2012
23:24
1
1
Run Code Online (Sandbox Code Playgroud)
(抱歉错误对齐,它不是程序的一部分)
现在我正在为删除记录的程序编写删除函数.到目前为止这是我的代码:
void masterSystem::cancelReservation()
{
string line;
string searchfor = "3740541120991";
int i=0;
ifstream myfile("records.txt");
while (getline(myfile, line))
{
cout << line << endl;
if (line==searchfor)
{
// DELETE THIS + THE NEXT 8 LINES
}
}
Run Code Online (Sandbox Code Playgroud)
}
我做了一些研究,发现没有简单的方法来访问文本文件的行,所以我们必须创建另一个文本文件.但问题是如何在将记录删除到新文本文件之前复制记录/数据?