我正在尝试访问这里的二进制文件,我有一个名为teacher.dat的文件,它是一个二进制文件。我该如何解决这个问题?
fstream fp;
Teacher obj;
int found = 0;
fp.open("teacher.dat", ios::in | ios::out);
while (fp.read((char*)&obj, sizeof(obj)) && found == 0)
{
if (obj.GetEmail() == email)
{
obj.display();
string password;
cout << "\nEnter The New password : ";
cin >> password;
obj.SetPassword(password);
//Error is indicated here
int pos = (-1)*sizeof(obj);
fp.seekp(pos, ios::cur);
fp.write((char*)&obj, sizeof(obj));
found = 1;
}
else{
cout << "\a Invalid email !" << endl;
}
}
答案 0 :(得分:0)
删除
else
{
cout << "\a Invalid email !" << endl;
}
并写
if (!found)
{
cout << "\a Invalid email !" << endl;
}
out of while()循环。
int pos = -1 * (signed)sizeof(obj);