feof
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <stdio.h> 中定义
|
||
int feof( FILE *stream ); |
||
如果给定的文件流的末尾检查已达到.
原文:
Checks if the end of the given file stream has been reached.
目录 |
[编辑] 参数
stream | - | 文件流检查
|
[编辑] 返回值
非零值,如果已到达流的末尾,否则0
原文:
nonzero value if the end of the stream has been reached, otherwise 0
[编辑] 注释
此功能只流的状态报告,报告的最近期的I / O操作,它不检查关联的数据源。例如,如果最近的I / O是一个fgetc,它返回一个文件的最后一个字节,
feof
返回非零。 fgetc失败和改变流的状态为“文件结束”。只有这样,feof
返回为零原文:
This function only reports the stream state as reported by the most recent I/O operation, it does not examine the associated data source. For example, if the most recent I/O was a fgetc, which returned the last byte of a file,
feof
returns non-zero. The next fgetc fails and changes the stream state to end-of-file. Only then feof
returns zero.在典型的使用中,输入流处理停止的任何错误;
feof
和ferrror然后用于区分不同的错误条件.原文:
In typical usage, input stream processing stops on any error;
feof
and ferrror are then used to distinguish between different error conditions.[编辑] 示例
#include <stdio.h> #include <stdlib.h> int main() { FILE* fp = fopen("test.txt", "r"); if(!fp) { perror("File opening failed"); return EXIT_FAILURE; } int c; // note: int, not char, required to handle EOF while ((c = fgetc(fp)) != EOF) { // typical file reading loop putchar(c); } if (ferror(fp)) puts("I/O error when reading"); else if (feof(fp)) puts("End of file reached successfully"); }
[编辑] 另请参阅
清除错误 (函数) | |
显示一个字符串相应的电流误差stderr 原文: displays a character string corresponding of the current error to stderr (函数) | |
检查文件错误 (函数) | |
C++ documentation for feof
|