472,951 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

mix mode file reading/writing?

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
Jul 19 '05 #1
4 6334
"john smith" <as**@asdf123asdf.net> wrote in message
news:bg***********@news.eecs.umich.edu...
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"
Jul 19 '05 #2
"Greg P." <no@spam.sam> wrote in message
news:fT****************@newsread3.news.pas.earthli nk.net...
"john smith" <as**@asdf123asdf.net> wrote in message
news:bg***********@news.eecs.umich.edu...
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
Jul 19 '05 #3
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" <es***@svd.co.kr> wrote in message
news:bg**********@news1.kornet.net...
"Greg P." <no@spam.sam> wrote in message
news:fT****************@newsread3.news.pas.earthli nk.net...
"john smith" <as**@asdf123asdf.net> wrote in message
news:bg***********@news.eecs.umich.edu...
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

Jul 19 '05 #4
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

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Guyon Morée | last post by:
what is the difference? if I open a text file in binary (rb) mode, it doesn't matter... the read() output is the same.
12
by: Aki Niimura | last post by:
Hello everyone, I started to use pickle to store the latest user settings for the tool I wrote. It writes out a pickled text file when it terminates and it restores the settings when it starts....
3
by: Alex Gerdemann | last post by:
Hello, I'm writing a program using the g++ compiler that runs under Cygwin in Windows, and have written the following: std::ifstream file; char buffer; std::string myString;...
7
by: smith4894 | last post by:
Hello all, I'm working on writing my own streambuf classes (to use in my custom ostream/isteam classes that will handle reading/writing data to a mmap'd file). When reading from the mmap...
1
by: raghu | last post by:
i want to know the difference between 'r' mode and 'r+' mode 1.i = open('c:\python25\integer.txt','w')-------->for writiing i.write('hai')--------->written some content in text file i =...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
10
by: Shraddha | last post by:
Why we should use binary mode of file? Where it is going to be actually needed???
13
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
15
by: =?ISO-8859-15?Q?L=E9na=EFc?= Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all, For some reasons, somewhere in a program, I'd like, if possible, to quickly parse a whole file before rewinding it and letting the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.