这是来自 IBM 的引述(C99标准中也有规定)
When you open a file for update, you can perform both input and output operations on the resulting stream. However, an output operation cannot be directly followed by an input operation without an intervening fflush subroutine call or a file positioning operation (fseek, fseeko, fseeko64, fsetpos, fsetpos64 or rewind subroutine). Also, an input operation cannot be directly followed by an output operation without an intervening flush or file positioning operation, unless the input operation encounters the end of the file.
为什么这是必要的?
最佳答案
操作可能会被缓冲以避免将每个字节单独写入磁盘。在开始读取之前,我们必须确保所有先前的写入都实际存储在磁盘上。
此外,无论如何都可能需要搜索来找到您想要阅读的内容。所以在实践中不是问题。
关于c - 为什么 fopen() 创建的文件流在输入和输出操作之间需要 fflush()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45898928/