Topic: iostream using binary io
Author: stephen.clamage_nospam@eng.sun.com (Steve Clamage)
Date: 1997/11/01 Raw View
On 31 Oct 97 14:13:51 GMT, "Felix" <felix@claritycomputing.com> wrote:
> In microsoft 4.2 the iostream operator could take 2 manipulators binary,
>and text.
>by streaming the binary manipulator the stream would do a setmode(binary) on
>its output, and streaming text would reverse the situation (translate \n to
>crlf etc).
>
>The 5.0 is supposed to be more ansi standard, and now these manipulators are
>gone. Actually in the old <iostream.h> they are still available, but in the
>new <iostream> they are gone.
>
>Is this a new part of the standard, and if so how do we change the stream
>state to write in binary and back to text mode.
Neither classic iostreams, the version in the draft standard, nor C
stdio provide any method for changing the mode of a stream between
text and binary. The stream mode is determined when it is opened and
cannot be changed.
The mode refers to the stream itself, not to data transfers. I don't
know of any file system that supports the notion of a file that is
both text and binary. (I would say that Unix files have NO type,
rather than saying that they are both text and binary.)
That is not to say you cannot write both text and binary data to the
same stream. To do that reliably, you open the stream in binary mode,
then use formatted I/O for text, and unformatted I/O for binary
values. No special manipulators or other functions are required, but
depending on the implementation you might miss some desired text
conversions.
A particular implementation might choose to provide additional
functionality via extensions to the I/O library to match the
characteristics of its file system. You would have to check the
documentation of the implementation to find out Your code would not be
portable if you took advantage of the extensions.
---
Steve Clamage, stephen.clamage_nospam@eng.sun.com
( Note: remove "_nospam" when replying )
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Felix" <felix@claritycomputing.com>
Date: 1997/10/31 Raw View
In microsoft 4.2 the iostream operator could take 2 manipulators binary,
and text.
by streaming the binary manipulator the stream would do a setmode(binary) on
its output, and streaming text would reverse the situation (translate \n to
crlf etc).
The 5.0 is supposed to be more ansi standard, and now these manipulators are
gone. Actually in the old <iostream.h> they are still available, but in the
new <iostream> they are gone.
Is this a new part of the standard, and if so how do we change the stream
state to write in binary and back to text mode.
I did a nasty hack like setmode(fileno(stdout), binary), but that only works
if cout IS actually using stdout. There must be a correct way in the new std
files to get the old behavior.
Thanks,
Felix
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]