gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:44:23 25 4
gpt4 key购买 nike

对于 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/

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