Hello guys, just getting into reading/writing to a file using the ofstream in c++. Even though I am successful in doing so and reading back from the file is ok, the file itself when viewed in windows explorer is over 300mb large!
And this was after I entered less text to store into the file. Originally it ended up being 1.12 gb large! :O
I am puzzled at the size, so I am hoping someone can point out what I am doing wrong. The following code is just a sample program to test the file writing/reading after researching the net.
Enter your id # 20006348
Enter your name doc archy
Enter your age 30
Enter your address 7 bird street
Enter the employee id you want to view 20006348
Id is 20006348
Name is doc archy
Age is 30
Address is 7 bird street
Press any key to continue . . .
The file with the above data, ended up being 306mb large.
LowestOne is right in that line 53 is the problem. All the bytes you skip by doing seekp will be part of the total file size. If it actually takes up all that space on the hard disk depends on you OS.
Another problem with your code is that you can't write an std::string to file like that. Internally std::string contains a pointer to the actual string data but only the pointer value will be written to the file.