gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 09:14:10 25 4
gpt4 key购买 nike

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

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

最佳答案

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 我建议你在提问之前阅读。它会给你很多关于可能的参数、返回值、类似函数等的信息。

此外,来自同一文档:

"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.

关于c - fopen() 中的 "rb+"和 "ab"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43978465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com