ios_base::openmode binary

Josuttis states the following about the binary openmode:


The flag binary configures the stream to suppress conversion of special characters or character sequences, such as end-of-line or end-of-file.

In OSs such as Windows or OS/2, a line end in text files is represented by 2 characters (CR and LF).

In normal text mode (ie, binary isn't set) newline characters are replaced by the 2-character sequence when reading and vice vera when writing, to avoid special processing.


The question is, shouldn't this instead read "In normal text mode (ie, binary isn't set) newline characters are replaced by the 2-character sequence when writing and vice versa when reading"?


The following link (https://stackoverflow.com/questions/229924/difference-between-files-writen-in-binary-and-text-mode) states:


•line feeds ('\n') will be translated to '\r\n" sequences on output
•carriage return/line feed sequences will be translated to line feeds on input.


Isn't this the opposite of what Josuttis says? So, which is it?

Thanks.
Last edited on
> The question is, shouldn't this instead read "In normal text mode (ie, binary isn't set) newline characters
> are replaced by the 2-character sequence when writing and vice versa when reading"?

Yes.

These character / character-sequence translations need not be limited to new line characters.

A text stream is an ordered sequence of characters composed into lines, each line
consisting of zero or more characters plus a terminating new-line character. Whether the
last line requires a terminating new-line character is implementation-defined. Characters
may have to be added, altered, or deleted on input and output to conform to differing
conventions for representing text in the host environment. Thus, there need not be a one-
to-one correspondence between the characters in a stream and those in the external
representation.
Data read in from a text stream will necessarily compare equal to the data
that were earlier written out to that stream only if: the data consist only of printing
characters and the control characters horizontal tab and new-line; no new-line character is
immediately preceded by space characters; and the last character is a new-line character.
Whether space characters that are written out immediately before a new-line character
appear when read in is implementation-defined. - C99
Topic archived. No new replies allowed.