Thank you very much.
Another question:
what are the codes to allow user to modify a record, for example, modify the record with stud_no 1234 to stud_no 2323? why when i modify a record using the following codes, that record(1234) does not changed. but it will insert the information(2323) as a new record at the end of student.dat?
My coding is like the follow:
void main()
{
.....
.....
cout<<"Enter the stud_no of the record you want to modify: ";
cin>>stuno;
modify(stuno);
}
void modify(int stuno)
{
student s;
fstream file;
file.open("student.dat", ios::app|ios:

ut|ios::in);
int count = findloc(stuno);
cout<<"\nDo you want to modify this record? (Y/N) ";
cin>>choice;
int location = (count - 1 ) * sizeof(s);
if(tolower(choice) == 'y')
{
cout<<"Enter stud_no:";
cin>>s.stud_no;
cout<<"Enter name: ";
cin>>s.name;
.....
.....
file.seekp(location);
file.write((char *) &s, sizeof(s));
}
}
int findloc(int stuno)
{
student s;
int n, endposition, count = 0;
fstream file;
file.open("student.dat", ios::app|ios:

ut|ios::in);
file.seekg(0, ios::end);
endposition = file.tellg();
n = endposition / sizeof(s);
file.seekg(0);
file.read((char *) &s, sizeof(s));
while(file.eof() == 0)
{
count++;
if(s.stud_no == stuno)
break;
file.read((char *) &s, sizeof(s));
}
if(count - 1 == n)
{
cout<<"There is no record with stud_no ("<<stuno<<")"<<endl<<endl;
}
file.close();
return count;
}