Well, I think I understand you OK:
your program doesn't work the way you think it should.
My suggestions were to get you to look at what your program actually does:
Code:
accfile >> accs[1].accno
If the first line of your data file has
then this statements stores the number 3 in the account number field of account number 1. Why?????
Then you read the rest of the line
Code:
getline (accfile, na);
This puts " accounts" into string na
Then this
Tries to calculate the integer value of the string, then does nothing with the result (The result is zero, by the way.)
Then you read the rest of the file. If each line has an account number and a name, you have read values into accs[0], accs[1], and accs[2]. If you put cout statements as I suggested, you can see whether the file data is what you think it is.
Now, after reading the accounts and performing a transaction, you close the file, then open the same file for writing and you write out the account information. Note that you did not write the first line "3 accounts". So the next time you try to use this as an input file, the program fails. (When you open a file for writing it destroys the previous contents of the file, so you must re-create the entire contents for it.)
Now, If I have misunderstood you, maybe you can tell me what you really mean.
Regards,
Dave