本文介绍了如何在c ++中更新文件中的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面提到的功能代码中。我无法在文件my.dat中更新余额(存款和取款)。请告诉我哪里做错了。 (我是新手)。
In below mentioned code of function. I am not able to update balance(deposits and withdrawals) in file my.dat. Please advise where am I doing it wrong. (I am a newbie).
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";
}
}
推荐答案
这篇关于如何在c ++中更新文件中的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!