I had retrieve my data(teacher account detail) from .dat file, and try to edit it.
Process of edit the data is perfect and the data is been edit and show correctly.
the problem is after go through edit process, one unknow data which is a teacher account is been inserted and showing unknown variable.
int Userid;
char UserPassword[50];
char UserType[50];
char UserName[50];
int contactnumber;
int a;
Teacher obj;
int found=0;
cout << "Please key in Teacher ID:" << endl;
cin >> temp;
f1.open("Teacher.dat", ios::binary | ios::in | ios::out);
while (f1.read((char*)&obj, sizeof(obj)) && found == 0)
{
if (obj.getid() == temp){
obj.Display();
cout << "\nEnter The New Details of Teacher" << endl;
int b = obj.getid();
Userid = b;
cout<<"\tInsert user Type:";
cin>>UserType;
cout<<"\tInsert user Password:";
cin>>UserPassword;
cout<<"\tInsert user Name:";
cin>>UserName;
cout<<"\tYr Contact Number:";
cin>>contactnumber;
obj.setUser(Userid,UserPassword,UserType,UserName,contactnumber);
int pos = (-1)*(int)sizeof(obj);
f1.seekp(pos, ios::cur);
f1.write((char*)&obj, sizeof(obj));
found = 1;
}
}
f1.close();
if (found == 0){cout << "Teacher not found!!" << endl;}
break;
cout<<"Please press ENTER to back to the menu ...";
cin.ignore();
cin.get();
}
here my display code:
1 2 3 4 5 6 7 8 9 10 11 12 13
Teacher obj2;
ifstream fp2;
cout<<"==============Teacher Listing===========\n";
fp2.open("teacher.dat",ios::binary);
while(fp2.read((char*)&obj2,sizeof(obj2)))
{
obj2.Display();
}
fp2.close();
cout<<"Please press ENTER to back to the menu ...";
cin.ignore();
cin.get();