TITLE: binary and text io in iostreams (Newsgroups: comp.std.c++, 1 Nov 97) FELIX: "Felix" > 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 they are still available, but in the > new 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. CLAMAGE: stephen.clamage@eng.sun.com (Steve Clamage) 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.