Dude you are calculating the pointer position wrong. When you write to a file, both the pointers move along. So after writing to file, calculate the no of characters written and then subtract that from the position where the pointers are at after writing. I mean after writing balance into file, instead of :
Code:
bal_l=fopen.tellg();
it should be:
Code:
bal_l=fopen.tellg()-sizeof(sw.balance);
but for for string vars, it should be:
Code:
bal_l=fopen.tellg()-len(str);
Actually the second thing you said is not possible as you want it to. The programs that allow inserting of items in their files make a separate copy of that file in memory or in a temporary files(like ms word). Then when the changes are finalized the original file is re-written by merging the contents of both.
So for your program the best strategy would be to make a data structure that can hold all the variables written in the file, since you are storing limited data of particular types in your file. On startup, read these settings and store them in vars then at the time of exiting, write them back to the file by opening the file in ios:

ut mode (effectively erasing the previous contents). This way you will have a temporary in-memory representation of your file while the program is running and a permanent copy of the changes will be saved to disk on exiting. This works perfectly well for program which edit small files.
MS Word uses the second approach as it is meant for editing files of all sizes.
Tell me if there are any more doubts

i'll be happy to help even though i am not at all concerned with Vodafone