Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > mix mode file reading/writing?

Reply
Thread Tools

mix mode file reading/writing?

 
 
john smith
Guest
Posts: n/a
 
      07-29-2003
Hi, I have a file format that is going to contain some parts in ascii, and
some parts with raw binary data. Should I open this file with ios::bin or
no?

For example:
filename: a.bin
number of points = 123
@@@begin data@@@
gibberish follows.....

@@@end data@@@

I will use the >> and << operators for the ascii parts, and iostream's read
and write functions for the binary parts. Any advice or suggestions will be
appreciated. Thanks.

Smith


 
Reply With Quote
 
 
 
 
Greg P.
Guest
Posts: n/a
 
      07-29-2003
"john smith" <(E-Mail Removed)> wrote in message
news:bg5c3p$1fbf$(E-Mail Removed)...
> Hi, I have a file format that is going to contain some parts in ascii, and
> some parts with raw binary data. Should I open this file with ios::bin or
> no?

The only difference between text and binary reads are the lack of \r\n reads
for binary. binary reads consider the characters, which mean end of line for
text, potential values themselves. I would suggest opening the file in
binary mode (for most of your file-related coding).
--

Regards,
Greg P.

Golden Rule of Open Source Programming:
"Don't whine about something unless you plan to implement it yourself"


 
Reply With Quote
 
 
 
 
ES Kim
Guest
Posts: n/a
 
      07-29-2003
"Greg P." <(E-Mail Removed)> wrote in message
news:fTqVa.1622$(E-Mail Removed) nk.net...
> "john smith" <(E-Mail Removed)> wrote in message
> news:bg5c3p$1fbf$(E-Mail Removed)...
> > Hi, I have a file format that is going to contain some parts in ascii, and
> > some parts with raw binary data. Should I open this file with ios::bin or
> > no?

> The only difference between text and binary reads are the lack of \r\n reads
> for binary. binary reads consider the characters, which mean end of line for
> text, potential values themselves. I would suggest opening the file in
> binary mode (for most of your file-related coding).
> --
>
> Regards,
> Greg P.
>
> Golden Rule of Open Source Programming:
> "Don't whine about something unless you plan to implement it yourself"
>
>


In addition, if you read a binary file in text mode, your program may
quit reading prematurely since it cannot detect the correct EOF position.

--
ES Kim


 
Reply With Quote
 
john smith
Guest
Posts: n/a
 
      07-30-2003
Hello, I still need some help with this.

When I open the file for writing in ASCII, it writes fine. Then I close it
and reopen it like so:
in.open(filename, ios_base::binary | ios_base:ate), and then I write my
data. When I open the file in notepad, the contents have become all
gibberish, like it's a binary file. But what I'm trying to do is something
like some Linux installation scripts. There is a text area which is human
readable, then it's followed by the binary area. The presumably the text
readable area is parsed by the shell and the binary area is executed. While
that's not what I'm trying to do, I am trying to write and read some raw
data, while being able to parse information about that data in raw text...

Any insights would be appreciated. Thanks in advance.

Smith

"ES Kim" <(E-Mail Removed)> wrote in message
news:bg5d3j$5ti$(E-Mail Removed)...
> "Greg P." <(E-Mail Removed)> wrote in message
> news:fTqVa.1622$(E-Mail Removed) nk.net...
> > "john smith" <(E-Mail Removed)> wrote in message
> > news:bg5c3p$1fbf$(E-Mail Removed)...
> > > Hi, I have a file format that is going to contain some parts in ascii,

and
> > > some parts with raw binary data. Should I open this file with

ios::bin or
> > > no?

> > The only difference between text and binary reads are the lack of \r\n

reads
> > for binary. binary reads consider the characters, which mean end of line

for
> > text, potential values themselves. I would suggest opening the file in
> > binary mode (for most of your file-related coding).
> > --
> >
> > Regards,
> > Greg P.
> >
> > Golden Rule of Open Source Programming:
> > "Don't whine about something unless you plan to implement it yourself"
> >
> >

>
> In addition, if you read a binary file in text mode, your program may
> quit reading prematurely since it cannot detect the correct EOF position.
>
> --
> ES Kim
>
>



 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      07-30-2003
john smith wrote:

> Hello, I still need some help with this.
>
> When I open the file for writing in ASCII, it writes fine. Then I close it
> and reopen it like so:
> in.open(filename, ios_base::binary | ios_base:ate), and then I write my
> data. When I open the file in notepad, the contents have become all
> gibberish, like it's a binary file. But what I'm trying to do is something
> like some Linux installation scripts. There is a text area which is human
> readable, then it's followed by the binary area. The presumably the text
> readable area is parsed by the shell and the binary area is executed. While
> that's not what I'm trying to do, I am trying to write and read some raw
> data, while being able to parse information about that data in raw text...
>
> Any insights would be appreciated. Thanks in advance.
>
> Smith


Please post your code and indicate where you are having problems.
Also state the expected behavior and the actual behavior.
This will allow people to assist you better.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re: mmm-mode, python-mode and doctest-mode? Edward Loper Python 0 08-07-2007 08:58 AM
Using mix mode compiling mailmetosandeep@gmail.com Java 2 09-25-2006 07:59 AM
Cross Session Error? Session state and kernel-mode output caching don't mix jason ASP .Net 0 08-30-2006 05:09 AM
mmm-mode, python-mode and doctest-mode? John J Lee Python 3 12-01-2005 08:35 PM
Safe Mode (?) - It is meant to be normal mode but looks like safe mode English Patient Computer Support 3 10-03-2004 11:10 PM



Advertisments