c。文本模式和二进制模式的区别 [英] Difference between text mode and binary mode in c

查看:121
本文介绍了c。文本模式和二进制模式的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文本模式下写入/读取文件时,新行字符被转换为回车符和换行符,即\\\
到\\\\\
,但在二进制模式下,这不会发生。



同样,ASCII值26将以文本模式写在文件末尾,但这不会在二进制模式下发生。



我知道这个问题在前面提到过,但是我没有发现任何推理。



我的意思是,这种行为只是为了区分文本和二进制模式,或者是否有任何特定的原因,并且在二进制模式下不写入ASCII值为26的文件。

从某种意义上说,二进制模式是原始的:没有任何东西被翻译,因为它没有这样做的基础。而在文本模式下,文件被解释为文本,因此(例如)行结尾被翻译成适当的表示。


while writing/reading of file in text mode, the new line character is translated in to carriage return and linefeed i.e \n to \r\n but in binary mode this doesn't happen.

Similarly, the ASCII value 26 will be written at the end of file in text mode but this doesn't happen in binary mode.

I know this question was asked earlier in SO but there i didn't find any reasoning for this behavior.

I mean, is this behavior is just to differentiate the text and binary mode or is there any specific reason of this translation and not writing ASCII value 26 in case of binary mode.

解决方案

In a sense, binary mode is "raw": nothing is translated, since it has no basis for doing so. Whereas in text mode, the file is interpreted as text, and thus (for example) line endings get translated to the appropriate representation.

这篇关于c。文本模式和二进制模式的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆