当我输入我想删除的用户 ID 时,它应该会删除该 ID 以及与之关联的其余数据。删除 ID 202210756 示例:
ID: 202210756
ID: 202210795
Name: franciz
Birthdate: 8/1/2003
Address: korea
Gender: male
Program: bsit
Year Level: 1
ID: 20221023
Name: marie
Birthdate: 1/1/2000
Address: manila
Gender: female
Program: bsit
Year Level: 1
但是当我运行代码时,它是这样的。
void Delete_Record(information* record){
fstream file("StudentData.txt");
ofstream write;
write.open("new.txt");
string data[MAX_LINES];
string choice;
int lines = 0;
cout << "Enter Student ID number to delete: ";
cin >> choice;
while (!file.eof())
{
getline(file, data[lines]);
lines++;
}
file.close();
file.open("StudentData.txt",ios::trunc);
for (int i = 0; i < lines; i++){
write<<data[i]<<endl;
if (data[i].find(choice) != string::npos)
{
int looper = 0;
while (looper !=6){
i++;
looper++;
break;
}
}
}
file.close();
write.close();
remove("StudentData.txt");
rename("new.txt","StudentData.txt");
system("cls");
cout<<"Student Deleted.\n";
}
这里是片段。我希望你们能帮我这个