nicht aktualisieren Ich möchte Betrag in Konto xyz abheben, aber wenn ich Betrag abziehe, kann ich neuen Betrag in Datei in bestimmter Position nicht aktualisieren (wo 1200 ist geschrieben) was kann ich tun?ich habe Projekt auf dem Banksystem in C++. Ich möchte Betrag abheben, aber wenn ich Betrag abziehe, kann ich neuen Betrag in Datei insbesondere Position
Dies ist meine Rückzugfunktion.
void withdraw()
{
ofstream f2("bank",ios::out | ios :: app);
ifstream f1("bank",ios::in | ios :: app);
f1.seekg(0);
long long a_num;
long double w_amount;
cout << "Enter Account Number :" << endl;
cin >> a_num;
Bank ac;
while (f1 >> acc_num >> name >> acc_type >> amount){
if(acc_num == a_num){
int g = f1.tellg();
cout << "Get" << g << endl;
int p=g;
acc_num=0;
f2.seekp(p,ios::beg);
cout << "Name :" << name << endl;
cout << "Account type :" << acc_type << endl;
cout << "balance :" << amount << endl;
cout << "Enter withdraw amount : " << endl;
cin >> w_amount;
amount = amount - w_amount;
cout << "Balance :" << amount << endl;
f2.seekp(p,ios::beg);
f2 << amount << endl;
}
}
}
Hier ist, was die Datei looks like:
bank.txt
123456789xyz savings 1200
123456789pyr current 1600
man kann nicht eine bestimmte Position in einer Datei aktualisieren. Sie müssen alles lesen, ändern, schreiben – user463035818