在下面提到的功能代码中。我无法更新 my.dat 文件中的余额(存款和取款)。请告知我在哪里做错了。(我是新手)。
void dep_with(int e, int f)
{
int amt;
int recordFind=0;
account ac;
ifstream updatedata("E:\\c++ Project\\final thoughts\\my.dat", ios::in|ios::out);
while(updatedata.read((char*) &ac, sizeof(ac)) && recordFind==0)
{
if(ac.get_account()==e)
{
ac.view_account();
if(f==1)
{
cout<<"\nEnter the amount to be deposited";
cin>>amt;
ac.deposits(amt);
}
if(f==2)
{
cout<<"\nEnter the amount to be withdraw";
cin>>amt;
ac.withdrawls(amt);
}
int pos=(-1)*sizeof(ac);
ofstream updatedata("E:\\c++ Project\\final thoughts\\my.dat", ios::in|ios::out|ios::app);
updatedata.seekp(pos,ios::cur);
updatedata.write((char*) &ac, sizeof(ac));
cout<<"\n\n\tRecord Updated";
recordFind=1;
}
}
updatedata.close();
if(recordFind==0)
{
cout<<"\n\nRecord not Found";
}
}