0
Suggestion About Bank Account Management system C++
Hello guys, this is a simple bank account management system which i create. I made it using function and some other basic stuff's without using classes and calling one into another. please suggest for improvements how can I make it less, easy, readable and standard. but before I have one problem in this one... when i run the file and create multiple new accounts, using deposit, and withdraw, its fine but when i quit it and open it again all the info inside data.txt file clears and everything is gone, how to save info permanently ?... https://code.sololearn.com/c2dXe2hIvo4j note: the code does not run well in this link because it has to save file inside pc. please check the code. waiting for your suggestions guys, thanks,
14 ответов
+ 4
then use ios::app instead of ios::out
+ 4
Amanullah I see you are using ios::trunc which is short for truncate. It means whenever you open the file all the contents of the file will be deleted. So open file in normal mode just use ios::out
+ 4
try ofstream instead of fstream
[Edit] : ofstream database;
database.open("data.txt", ios::out | ios::trunc);
+ 4
ifstream is used for reading files and ofstream is used to write into files.
+ 4
yup, I check your code in my laptop and will see what's the issue
+ 3
I think you aren't actually writing any thing to file, you have just opened it.
All what you are doing is printing every thing on the console.
To write into a file you need to use file handler instead of cout.
In your case you would use
database << "Write anything to file" << endl;
Note:
You can use all escape sequences and can do anything like you do with your cout
+ 3
I checked the code, it's working fine. Saving output in a file and when I reopen the file every thing is saved. But there's one thing when ever you run your program the new data is overwritten with the previous data and that's why you loose the old data. Is that what you are talking about?
+ 1
ahh nAutAxH AhmAd thanks alot. problem solved.
now can u suggest some improvements in my code in any case like making it more readable,easy,standard and ...
0
database<<"Account Type - "<<accType<<endl; isnt is correct to save account type in file ? it is saving in file but when closing console and opening again then file is empty again. nAutAxH AhmAd
0
nAutAxH AhmAd before i didnt include that but no change. still when i run program again data is cleared... and i used trunc just to remove duplicated data. can u please run my code in pc and see what i mean ? thanks
0
i used it before when it doesnt work i tried changing it to ifstream still not works. now again i tried but not worked
0
and fstream is used for both i tried both of then but not works...
0
ok i am waiting
0
yes. when i close the program and run it again even if i put different info it just clears all the previous data and just saves the new one. i want it to save the data anytime it runs