Suggestion About Bank Account Management system C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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,

10th Sep 2018, 4:52 PM
AMANULLAH
AMANULLAH - avatar
14 Answers
+ 4
then use ios::app instead of ios::out
11th Sep 2018, 6:21 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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
11th Sep 2018, 5:18 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 4
try ofstream instead of fstream [Edit] : ofstream database; database.open("data.txt", ios::out | ios::trunc);
11th Sep 2018, 5:24 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 4
ifstream is used for reading files and ofstream is used to write into files.
11th Sep 2018, 5:29 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 4
yup, I check your code in my laptop and will see what's the issue
11th Sep 2018, 5:32 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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
10th Sep 2018, 6:23 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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?
11th Sep 2018, 6:10 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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 ...
11th Sep 2018, 6:32 AM
AMANULLAH
AMANULLAH - avatar
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
11th Sep 2018, 2:07 AM
AMANULLAH
AMANULLAH - avatar
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
11th Sep 2018, 5:23 AM
AMANULLAH
AMANULLAH - avatar
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
11th Sep 2018, 5:28 AM
AMANULLAH
AMANULLAH - avatar
0
and fstream is used for both i tried both of then but not works...
11th Sep 2018, 5:31 AM
AMANULLAH
AMANULLAH - avatar
0
ok i am waiting
11th Sep 2018, 5:33 AM
AMANULLAH
AMANULLAH - avatar
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
11th Sep 2018, 6:18 AM
AMANULLAH
AMANULLAH - avatar