Need Help in C++

I have write the following code. Now I want help to update File. If user enters Withdrawal then the amount should be deducted and balance should be replaced in file or if user enter Deposit than after adding the deposit amuont in balnace the net balnace shuold be updated. the Data text File is as below

Data.txt
01 abc 15000
02 aaa 20000
03 1ab 500
04 xyz 12500
05 s25 25000


#include <iostream.h>
#include <stdlib.h>
#include <string>
#include <fstream>

class openAccount
{
protected:
string AcNo;
string pass;
int oBalance;
public:
openAccount()
{
cout<<"Enter Account No. ";
cin>>AcNo;
cout<<"Enter Pasword";
cin>>pass;
cout<<"Enter Op Balance";
cin>>oBalance;
ofstream ab("Data.txt",ios::app);
if(!ab)
cout<<"Error!\n\n Your Account Cannot be Opened at this Time\n";
ab<<AcNo<<'\t'<<pass<<'\t'<<oBalance<<endl;
cout<<"Your Account Has Been Created Successfully\n";
}
~openAccount(){}
};

class Account
{
public:
string ID;
string pass;
int Balance;
};



void transaction()
{
int d;
string a,b,c;
Account au;

cout<<"Enter Account No. ";
cin>>a;
cout<<"Enter Pasword";
cin>>c;
cout<<"Enter Transaction Type";
cin>>b;
cout<<"Enter Amount";
cin>>d;

cout<<"\n\nProcessing . . . . ";

ifstream readFile("Data.txt",ios::in|ios::out);

if(!readFile)
cout<<"Your Transaction not process at this time\n";

while((readFile>>au.ID>>au.pass>>au.Balance)!=NULL)

{
if(a==au.ID&&c==au.pass)
{
cout<<"Your Account Balance Is = "<<au.Balance<<endl;
break;
}

};

if(readFile==NULL)
cout<<"\n\nPassword is Wrong or Account Does not Exist";

}

int main()
{

int AcNo;
cout<<"================================"<<endl;
cout<<"= WELCOME TO VIRTUAL BANK LTD. = "<<endl;
cout<<"================================"<<endl;
cout<<"= ="<<endl;
cout<<"= ="<<endl;
cout<<"= 1. Open a New Account ="<<endl;
cout<<"= 2. Open an Existing Account ="<<endl;
cout<<"= ="<<endl;
cout<<"= ="<<endl;
cout<<"================================"<<endl;
cin>>AcNo;
if(AcNo==1)
openAccount();
if(AcNo==2)
transaction();



system("PAUSE");
return 0;
}
updating a file is not a easy thing, in native languages like c++, there many third party library available for this. But the standard way is to copy everything else other than that particular record, into a new file, then delete the older file, then rename the older file to newer one.
Topic archived. No new replies allowed.