首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::feof

Defined in header <cstdio>

?

?

int feof( std::FILE* stream );

?

?

检查是否已到达给定文件流的结束。

参数

stream

-

the file stream to check

返回值

如果已到达流的末尾,则为非零值。?0?...

注记

此函数只报告最新I/O操作报告的流状态,不检查关联数据源。例如,如果最近的I/O是std::fgetc返回文件的最后一个字节,std::feof返回零。下一个std::fgetc失败,并将流状态更改为文件末.只有那时std::feof返回非零。

在通常情况下,输入流处理会在任何错误上停止;feofstd::ferror然后用于区分不同的错误条件。

二次

代码语言:javascript
复制
#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");
 
    std::fclose(fp);
}

二次

另见

eof

checks if end-of-file has been reached (public member function of std::basic_ios)

clearerr

clears errors (function)

perror

displays a character string corresponding of the current error to stderr (function)

ferror

checks for a file error (function)

c文件

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com