fopen() 中的 "rb+" 和 "ab" 有什么区别?

What is the difference between "rb+" and "ab" in fopen()?

我不明白在 C 中使用 fopen()"ab""rb+" 模式之间的区别。

为什么我会选择一个而不是另一个?

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 documentation,我建议您在提问前阅读。它将为您提供大量有关可能参数、return 值、类似功能等的信息。

此外,来自同一文档:

"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+" = read/update: Open a file for update (both for input and output). The file must exist.