c++文件流如何删除数据

2024-12-02 11:55:29
推荐回答(1个)
回答(1):

void delrecord()
{
ifstream da("Result.txt", ios_base::in);string str; bool flag = true;
ofstream data("return.txt", ios_base::out);
char a[20];
if (!da)
{
cout<<"找不到文件!!!!"< return;
}
cout<<"请输入你要删除人的姓名"< cin>>a;
while ( da>>TelInfo.name)
{
getline(da, str);
if (strcmp(TelInfo.name,a)==0)
{
cout < cout< flag=false;
break;
}

data< <<" "< }
if(flag)cout<<"没有该人"< else
{
while (getline(da, str))
{
data< }
da.close();
data.close();
ifstream in("return.txt", ios::in);
ofstream out("Result.txt", ios::out);
if (!out || !in)
{
cout< return;
}
while (getline(in, str))
{
out< }
out.close();
in.close();
cout <