I need some help overwriting a balance amount in two files, currently all I have it do is find the entry in the one file, read in all the information, and than add the deposit amount to it, but I can't overwrite the amount pulled from the file.
To clear any confusion:
Checking Balance: 500
saving balance: 200
transfer 200 from checking to savings
new checking balance: 300
new saving balance: 400
Any help would be greatly appreciated. =) Thanks in advance for your time.
The file is not a fixed-format file (meaning that each field may vary in size), so you really have no choice but to read the entire file, make your changes, and then write the entire file back out again. I'm not sure why you are opening the files as 'binary'.
Lines 31 through 36 don't do what you think they are doing. To convert a number from string:
1 2 3 4 5 6 7 8 9 10 11 12
// string2int()
// Converts a string of the form "123" or "-123" to its integer representation.
// Throws an int on failure.
//
int string2int( const std::string& s )
{
int result;
std::istringstream ss( s );
ss >> result;
if (ss.eof()) return result;
throw 1;
}
Remember, a single char is not the same as a "character string", like char input_number[ 22 ];. In any case, you should avoid char[] arrays and use std::string instead: it makes your program more robust.