c++文件操作怎样删除特定的记录?

c++文件操作怎样删除特定的记录?如图所示,有三条记录每条都用接点存好,在一个TXT文件中,现在要删除第二条记录,应该怎么写代码?使删除后只有两条记录,求大神写个小例子,谢谢

把txt中的东西读取到一个数据结构中,把第二条删了,然后输出到txt追问

就是不会啊

追答#include<iostream>
#include<fstream>
#include<string>
#include<list>
using namespace std;
struct A
{
 string id;
 string sex;
 int age;
 string local;
 string project;
};
int main()
{
 list<A> T;
 ifstream fin;
 fin.open("1.txt");
 A temp;
 while (fin >> temp.id >> temp.sex >> temp.age >> temp.local >> temp.project)
 {
  T.push_back(temp);
 }
 auto ite = T.begin();
 T.erase(ite++);
 fin.close();
 ofstream fout;
 fout.open("1.txt");
 ite = T.begin();
 auto eite = T.end();
 while (ite != eite)
 {
  cout << ite->id << ends << ite->sex << ends << ite->age << ends << ite->local << ends << ite->project;
 }
 fout.close();
 system("pause");
 return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答