Problem with file updating using seekp()

I have been creating this program for a student registration system. For the file handling So far I can write in to a file , view all records, and search a single record. now i got the problem with updating details . my coding is as bellow ..

void file_update() {
int r;
struct student stu;
fstream stu_file;
cout <<"========Update Record======"<< endl;
stu_file.open("student.txt", ios::app );


cout <<"Record Number to update the record: ";
cin >> r;

stu_file.seekp((sizeof (struct student)*r),ios::beg);

cout << " Name :";
gets(stu.name);
cout << " Age : ";
cin >> stu.age;

if(!stu_file.write((char*) &stu,sizeof(struct student)))
cout << " Error " << endl;
else
cout << " Record has been updated" << endl;
stu_file.close();
cout <<"=========End========"<< endl;
getch();

}

My problem is it won't update the record. it just adding a new record. would be greateful if someone can show me what I have done wrong.
Topic archived. No new replies allowed.