std::feof
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <cstdio> 中定义
|
||
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是一个std::fgetc,它返回一个文件的最后一个字节,
std::feof
返回非零。 std::fgetc失败和改变流的状态为“文件结束”。只有这样,std::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 std::fgetc, which returned the last byte of a file,
std::feof
returns non-zero. The next std::fgetc fails and changes the stream state to end-of-file. Only then std::feof
returns zero.在典型的使用中,输入流处理停止的任何错误;
feof
和std::ferrror然后用于区分不同的错误条件.原文:
In typical usage, input stream processing stops on any error;
feof
and std::ferrror are then used to distinguish between different error conditions.[编辑] 示例
#include <cstdio> #include <cstdlib> int main() { FILE* fp = std::fopen("test.txt", "r"); if(!fp) { std::perror("File opening failed"); return EXIT_FAILURE; } int c; // note: int, not char, required to handle EOF while ((c = std::fgetc(fp)) != EOF) { // standard C I/O file reading loop std::putchar(c); } if (std::ferror(fp)) std::puts("I/O error when reading"); else if (std::feof(fp)) std::puts("End of file reached successfully"); }
[编辑] 另请参阅
如果最终文件的检查已经达到了 原文: checks if end-of-file has been reached (公共成员函数of std::basic_ios )
| |
清除错误 (函数) | |
显示一个字符串相应的电流误差stderr 原文: displays a character string corresponding of the current error to stderr (函数) | |
检查文件错误 (函数) | |
C documentation for feof
|