I'm making a student management system. All is working well, except the Delete Student Info
function. I'm totally new in studying the C++ language.
When I try to use the Delete
function, it will result like this, like a loop:
And this is my delete code:
void student::deleted()
{
system("cls");
fstream file, file1;
int found = 0;
string snum;
cout<<"\t\t\t\t-------------------------------------------\t\t\t"<<endl;
cout<<"\t\t\t\t---------Delete Student Information--------\t\t\t"<<endl;
file.open("Records.txt", ios::in);
if (!file)
{
cout << "\n\t\t\tNo information is available.";
file.close();
}
else
{
cout <<"\nEnter Student Number you want to remove: ";
cin >> snum;
file1.open("Records1.txt", ios::app | ios::out);
file >> student_num >> name >> bday >> address >> gender >> degree >> year;
while (!file.eof())
{
if(snum != student_num)
{
file1 << " " << student_num << " " << name << " " << bday << " " << address << " " << gender << " " << degree << " " << year ;
} else
{
found==0;
cout <<"\n\t\t\tSuccessfully Deleted.";
}
}
file1 >> student_num >> name >> bday >>address >> gender >> degree >> year ;
if (found == 0)
{
cout <<"\n\t\t\tStudent Number not found.";
}
file1.close();
file.close();
remove("Records.txt");
rename("Records.txt", "NewRecords.txt");
}
All is working on my program, except this delete function. I hope you can enlighten me with knowledge I still not know.