c - 关闭文件时 feof() 的返回值是多少?

标签 c file

对于 FILE* 流,如果我读取尽可能多的数据,feof(stream) 返回非零值。然后,如果我关闭流,它 feof(stream) 会继续返回一个非零值吗? 有保证吗?

最佳答案

在一个关闭的文件上调用 feof() 是没有意义的(实际上比没有意义更糟糕——它是未定义的所以任何事情都有可能发生)。

来自 C 标准:

The value of a pointer to a FILE object is indeterminate after the associated file is closed (including the standard text streams).

A successful call to the fclose function causes the stream pointed to by stream to be flushed and the associated file to be closed. Any unwritten buffered data for the stream are delivered to the host environment to be written to the file; any unread buffered data are discarded. Whether or not the call succeeds, the stream is disassociated from the file and any buffer set by the setbuf or setvbuf function is disassociated from the stream (and deallocated if it was automatically allocated).

关于c - 关闭文件时 feof() 的返回值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/179543/

相关文章:

android - 将文件保存在 SD 卡上,写入文件大小 0

c++ - 高级文件和字符串操作

file - 在谷歌 GWT 中读取文本文件?

c - 将基本名称与完整文件路径分开

ios - 如何在 objective-c 中比较自定义 sqlite 排序规则中的字符?

java - 编程语言中的堆栈性能

java - 删除带有java文件的文件

c - 你如何在C中的Epoch中获取文件的最后访问时间?

c - 想了解 C 数组行为

带 print 的 CMake 构建后输出命令