Difference in using read/write when stream is opened with/without ios::binary mode

后端 未结 2 587
青春惊慌失措
青春惊慌失措 2020-12-06 20:24

In my experiments with the following code snippet, I did not find any particular difference whether i created the streams with/without the ios:binary mode:

i         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 21:02

    The only difference between binary and text mode is how the '\n' character is treated.

    In binary mode there is no translation.

    In text mode \n is translated on write into a the end of line sequence.
    In text mode end of line sequence is translated on read into \n.

    The end of line sequence is platform dependant.

    Examples:

    ASCII based systems:

    LF    ('\0x0A'):      Multics, Mac OS X, BeOS, Amiga, RISC OS
    CRLF  ('\0x0D\0x0A'): Microsoft Windows, DEC TOPS-10, RT-11
    CR:   ('\0x0D'):      TRS-80, Mac OS Pre X
    RS:   ('\0x1E'):      QNX pre-POSIX implementation.
    

提交回复
热议问题