Hey guys
So, I what I am trying to accomplish is I have a account class and a bank class. my bank class uses a map which stores the account object. upon starting the program the bank class will read the file from a txt and store them into my map. i have a static variable which keeps track of the account number which starts as 1. so the problem is when i start my program the initial txt file is empty. however my map is storing a 0. the bottom is my constructor for bank class.
yes it does upon running the code using a empty txt file. exiting the code right away should not have input anything back into the txt. but an account 0 was shown on the txt
a filestream's eof is set only AFTER you try to read past the end of the file. Opening up an empty file the eof flag is not set initially. Line 5 you try to read a from the file without testing you've actually read any valid data. If the data is bad you then add that bogus data into mybank. You loop back to the beginning of your while and only then after the bad read is the file's eof set.
my destrutor will read my map and store the data into my txt file
It's conceptually difficult to do substantive work in a destructor because destructors, conceptually, may not fail. Substantive work, however, generally can fail.
This is a major issue if your software was actually managing my money.
You might be better off with an explicit commit function which must be called to make any irreversible change. For instance, make changes into a temporary buffer, and write bank.txt only upon explicit request.