utkarsh009 0 Newbie Poster

If i uncomment the lines in between, all the records get deleted. Why??

void Hatao()
   {
    int no;
    system("cls");
    cout<<"\n\n\n\tDelete Record";
top:cout<<"\n\nPlease Enter The roll number of student You Want To Delete: ";
    cin>>no;
    fp.open("student.dat",ios::in|ios::ate);
    fp.seekp(0,ios::beg);
    fp.seekg(0,ios::beg);
    fstream fp2;
    fp2.open("Temp.dat",ios::out);
    //int flag=0;
    //if (st.retrollno()==no)
    //flag=1;
    //if (flag==0)
    //{
    //    cout<<"\nRecord does not exist!!";
    //    char choice;
    //  cout<<"\nDo you want to enter another Roll no.??(y/n): ";
    //    cin>>choice;
    //    if((choice=='y')||(choice=='Y'))
    //    {
    //        system("cls");
    //        fp2.close();
    //        fp.close();
    //        goto top;
    //    }
    //    else
    //    {
    //        fp2.close();
    //        fp.close();
    //        goto bot;
    //     }
    //}
    while(fp.read((char*)&st,sizeof(student)))
    {
     if(st.retrollno()!=no)
        {
         fp2.write((char*)&st,sizeof(student));
         }
     }
    fp2.close();
    fp.close();
    remove("student.dat");
    rename("Temp.dat","student.dat");
    cout<<"\n\n\tRecord Deleted ..";
bot:cout<<"\n\n\tPress <ENTER> to continue...";
    cin.get(); cin.get();
    }