Difference between files written in binary and text mode

前端 未结 7 1802
南旧
南旧 2020-11-22 14:20

What translation occurs when writing to a file that was opened in text mode that does not occur in binary mode? Specifically in MS Visual C.

unsigned char bu         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 14:58

    In text mode, a newline "\n" may be converted to a carriage return + newline "\r\n"

    Usually you'll want to open in binary mode. Trying to read any binary data in text mode won't work, it will be corrupted. You can read text ok in binary mode though - it just won't do automatic translations of "\n" to "\r\n".

    See fopen

提交回复
热议问题