"rb +"与"rb +"之间的区别是什么?和"ab"在fopen()中? [英] What is the difference between "rb+" and "ab" in fopen()?
问题描述
在C语言中使用fopen()
时,我不理解"ab"
和"rb+"
模式之间的区别.
I do not understand the difference between the "ab"
and "rb+"
modes when using fopen()
in C.
为什么我要选择一个而不是另一个?
Why would I choose one instead of the other?
推荐答案
使用上面的模式说明符,文件将作为文本文件打开.在 为了以二进制文件形式打开文件,必须使用
"b"
字符 包含在模式字符串中.这个额外的"b"
字符可以 被附加在字符串的末尾(因此进行以下操作) 复合模式:"rb"
,"wb"
,"ab"
,"r+b
,"w+b"
,"a+b"
)或被插入 字母和"+"
符号之间的混合模式("rb+"
,"wb+"
,"ab+"
).
With the mode specifiers above the file is open as a text file. In order to open a file as a binary file, a
"b"
character has to be included in the mode string. This additional"b"
character can either be appended at the end of the string (thus making the following compound modes:"rb"
,"wb"
,"ab"
,"r+b
","w+b"
,"a+b"
) or be inserted between the letter and the"+"
sign for the mixed modes ("rb+"
,"wb+"
,"ab+"
).
摘录自 fopen
文档,我建议您在提出问题之前先阅读一下.它将为您提供有关可能的参数,返回值,类似函数等的大量信息.
From fopen
documentation which I advise you read before asking questions. It will give you a lot of information about possible parameters, return values, similar functions etc.
同样,来自同一文档:
"a"
= 附加:打开文件以在文件末尾输出.输出操作始终将数据写入文件的末尾,然后对其进行扩展.重新定位操作(fseek
,fsetpos
,rewind
)将被忽略.如果该文件不存在,则会创建该文件.
"a"
= append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek
,fsetpos
,rewind
) are ignored. The file is created if it does not exist.
"r+"
= 读取/更新:打开文件进行更新(用于输入和输出).该文件必须存在.
"r+"
= read/update: Open a file for update (both for input and output). The file must exist.
这篇关于"rb +"与"rb +"之间的区别是什么?和"ab"在fopen()中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!