Link to home
Start Free TrialLog in
Avatar of pangelll
pangelll

asked on

Overwriting a record in a binary file

Hi, here I am trying to overwrite a record in a binary file, however it overwrites the entire file with the write function.  I have attempted to use ios::trunc in the fstream constructor, but still produces same result.

*in this example code i'm simply trying to overwrite the first record, I can retrieve this.
fstream f("records.bin", ios::binary | ios::out);
 
f.seekp(0);
f.write(reinterpret_cast<const char*>(&binPerson),sizeof(binPerson));
f.close();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pangelll
pangelll

ASKER

wow! Thankyou.