Connecting Tech Pros Worldwide Forums | Help | Site Map

Updating a binary file?

lanturn@gmail.com
Guest
 
Posts: n/a
#1: Jan 1 '06
Hello all,

I'm having problems updating a binary file as when I open with the
flags ios::binary and ios::out the file is cleared of its data. Is
there any way I can retain its original contents and make changes to a
certain region only?

Thanks in advance,
Lanturn


David Harmon
Guest
 
Posts: n/a
#2: Jan 1 '06

re: Updating a binary file?


On 1 Jan 2006 07:08:09 -0800 in comp.lang.c++, "lanturn@gmail.com"
<lanturn@gmail.com> wrote,[color=blue]
>Hello all,
>
>I'm having problems updating a binary file as when I open with the
>flags ios::binary and ios::out the file is cleared of its data. Is
>there any way I can retain its original contents and make changes to a
>certain region only?[/color]

Open with ios::in|ios::out

lanturn@gmail.com
Guest
 
Posts: n/a
#3: Jan 2 '06

re: Updating a binary file?


Hmm thanks... it seems to work but it always modifies the last variable
in the struct at the last record such that it contains a random value.
As a sidenote, is the ios::binary flag optional then?

David Harmon
Guest
 
Posts: n/a
#4: Jan 2 '06

re: Updating a binary file?


On 1 Jan 2006 19:29:46 -0800 in comp.lang.c++, "lanturn@gmail.com"
<lanturn@gmail.com> wrote,[color=blue]
>Hmm thanks... it seems to work but it always modifies the last variable
>in the struct at the last record such that it contains a random value.
>As a sidenote, is the ios::binary flag optional then?[/color]

No, I should have written ios::in|ios::out|ios::binary. But you
already had that part. You should open in the correct mode to be
correct, but some systems may have no actual difference between text
and binary.

What's that about random values? Mind your seekp() and seekg()s,
and post example code if you still have trouble.

lanturn@gmail.com
Guest
 
Posts: n/a
#5: Jan 2 '06

re: Updating a binary file?


Gee... thanks a lot..
It works perfectly now... It must have occurred when I opened without
the binary mode.

Closed Thread