Abhishek Dwivedi
TechFreakiez.com
Hi Guys,
Am trying to edit a file in C++. Am using TurboC++ (and have to stick to it only ).
I have to functions, find_detail() and balance_update().
What am trying to do is find the position of balance in the file, store it in a int variable, then in balance_update function, am going to that position using seekg() and replacing the old balance with new balance.
The problem is that the old balance is not replaced and the output is given in the end of file...
Can anyone please help me fix this? is it a prblm of bal_n and bal_s variables or something else?
thx in advance
Am trying to edit a file in C++. Am using TurboC++ (and have to stick to it only ).
I have to functions, find_detail() and balance_update().
What am trying to do is find the position of balance in the file, store it in a int variable, then in balance_update function, am going to that position using seekg() and replacing the old balance with new balance.
The problem is that the old balance is not replaced and the output is given in the end of file...
Can anyone please help me fix this? is it a prblm of bal_n and bal_s variables or something else?
Code:
void find_detail()
{
ifstream fopen(current_user, ios::in);
fopen>>sw.balance;
bal_l=fopen.tellg();
bal_s=ceil(log10(sw.balance));
fopen>>sw.age;
age_l=fopen.tellg();
age_s=ceil(log10(sw.age)); //find numbr of digits
fopen.close();
}
Code:
void balance_update()
{
float bal=0.0;
ofstream filebalance(current_user, ios::app);
find_detail();
filebalance.seekp(bal_l-bal_s);
filebalance<<bal;
filebalance.close();
}
thx in advance