fopen时w与wb的区别

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

fopen时w与wb的区别
fopen时w与wb的区别
今天做了个⼩程序,把⼩个⼩进制⼩件分割为多个1.44M的⼩件,但分割完成后,发现很多⼩件的⼩⼩都超过1.44M。

在⼩上搜索了下,发现时fopen是的参数部队。

“w”表⼩为⼩本⼩件。

⼩则会把⼩件中的“0A”变为“0D0A”,因为某些⼩件系统认为“0A”为⼩本⼩件的换⼩符,windows认为“0D0A”为⼩本⼩件的换⼩符,为了兼容其他⼩件系统(如从linux 拷贝来的⼩件),windows上的fopen函数做了这样的格式转换。

如果我记得没错的
话,linux与vxworks上不会做这样的转换,所以可以说使⼩“w”,其属性要看所在的平台。

“wb参数”表⼩为⼩进制⼩件,则样⼩件系统会按纯粹的⼩进制格式进⼩操作,因此也就不存在格式转换的问题了。

综上,如果使⼩的是⼩进制⼩件,⼩定要使⼩“wb”参数,这样肯定错不了。

参数“wt”:
“w”其实默认就是“wt”,即write in text mode。

下⼩是msdn中队这⼩个参数的解释:
“If t or b is not given in mode, the default translation mode is defined by the global variable . ”
“The default setting of _fmode is _O_TEXT for text-mode translation. _O_BINARY is the setting for binary mode.
You can change the value of _fmodein either of two ways:
Link with BINMODE.OBJ. This changes the initial setting of _fmode to _O_BINARY, causing all files except stdin, stdout, and stderrto be opened in binary mode.
Change the value of _fmode directly by setting it in your program. ”。

相关文档
最新文档