feof()在关闭文件上的返回值是什么? [英] What is the return value of feof() on a closed file?

查看:176
本文介绍了feof()在关闭文件上的返回值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

for a FILE* stream, if I read as much data as possible, feof(stream) returns me non-zero. Then, If I fclose stream, it feof(stream) will continue to returns me a non-zero value? Is it GUARANTEED?

推荐答案

在关闭的文件上调用feof()是没有意义的(实际上比没有意义更糟-它是未定义的,因此任何事情都可能发生).

Calling feof() on a closed file is meaningless (actually worse than meaningless - it's undefined so anything can happen).

根据C标准:

指向FILE的指针的值 后的对象是不确定的 关联文件已关闭(包括 标准文本流).

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

成功调用了fclose 函数导致流指向 按要冲洗的流和 关联文件将被关闭.任何 流的未写缓冲数据 交付给主机环境 写入文件;任何未读 缓冲的数据将被丢弃.无论 呼叫是否成功,流 已从文件和任何其他文件中取消关联 由setbuf或setvbuf设置的缓冲区 功能与 流(如果是 自动分配).

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

这篇关于feof()在关闭文件上的返回值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆