Connecting Tech Pros Worldwide Help | Site Map

Updating a binary file?

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 1st, 2006, 02:15 PM
lanturn@gmail.com
Guest
 
Posts: n/a
Default Updating a binary file?

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, 05:05 PM
David Harmon
Guest
 
Posts: n/a
Default 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, 02:45 AM
lanturn@gmail.com
Guest
 
Posts: n/a
Default 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, 05:25 AM
David Harmon
Guest
 
Posts: n/a
Default 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, 05:35 AM
lanturn@gmail.com
Guest
 
Posts: n/a
Default Re: Updating a binary file?

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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.