Connecting Tech Pros Worldwide Help | Site Map

Updating a binary file?

  #1  
Old January 1st, 2006, 03:15 PM
lanturn@gmail.com
Guest
 
Posts: n/a
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

  #2  
Old January 1st, 2006, 06:05 PM
David Harmon
Guest
 
Posts: n/a

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

  #3  
Old January 2nd, 2006, 03:45 AM
lanturn@gmail.com
Guest
 
Posts: n/a

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?

  #4  
Old January 2nd, 2006, 06:25 AM
David Harmon
Guest
 
Posts: n/a

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.

  #5  
Old January 2nd, 2006, 06:35 AM
lanturn@gmail.com
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to update a text file =?Utf-8?B?RGF2aWRF?= answers 5 May 20th, 2007 07:55 AM
What are multi-file assemblies used for??? Bob Rock answers 1 November 16th, 2005 08:34 AM
Ethics of linking to a binary Lee Phillips answers 27 July 20th, 2005 07:59 PM
How to raise File Download box in WindowsCE client Pedro Fonseca answers 2 July 17th, 2005 06:36 AM