delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1992/09/18/17:41:23

Subject: Re: Outputting binary data to a file
To: djgpp AT sun DOT soe DOT clarkson DOT edu (DJ's GPP mailing list)
Date: Fri, 18 Sep 92 17:05:42 EDT
From: Stephen Turnbull <turnbull AT ecolan DOT sbs DOT ohio-state DOT edu>

> >The faq seems to indicate you can set binary mode for file IO if you are
> >using C, but I can't find anything for C++.
> 
> fopen(...,"wb") gives you a binary stream, as does open(...,O_BINARY).
> I don't think there's a mechanism for C++ stream objects.
> 
> DJ
I don't have my C++ manuals at work; they're at home where most of the
stuff I like to do is.  However, at least in Zortech C++ 2.1 (what
I'm most familiar with), which does not have cfront 2.0 compatibility,
the C++ streams are a layer on top of the C streams which lie on top
of the OS stream.  In ZTC++ one has to actually FILE *fp = fopen(...)
the file, then connect a stream to it using say istream is(fp,...).
If GNU C++ 2.2.2 has a more transparent mechanism for opening a text
file as a stream, I betcha you can still do it long way around,
opening the file in binary mode, then connecting the stream to it.
    Second, what do want to do with this "binary" file?  There are a
lot of things that you can toggle after the stream has been opened,
like nl<->crlf translation, raw vs. skipwhite, treatment of EOF, and
so on.  Look in the *stre*.h include files; I bet you find what you
need.
-- 
 
Stephen Turnbull
The Ohio State University, Department of Economics
410 Arps Hall, 1945 N. High St., Columbus, OH  43210-1172  USA
Phone: (614) 292-0654  Fax: ...-3906  Email: turnbull DOT 1 AT osu DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019