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

std::fclose

Defined in header <cstdio>

?

?

int fclose( std::FILE* stream );

?

?

关闭给定的文件流。任何未写入的缓冲数据都会被刷新到操作系统。任何未读取的缓冲数据都会被丢弃。

无论操作成功与否,流都不再与文件相关联,而缓冲区将由std::setbufstd::setvbuf,如果有的话,如果使用自动分配,也会被取消关联和解除分配。

如果指针的值为stream后用fclose退货。

参数

stream

-

the file stream to close

返回值

?0?在成功的时候,EOF否则。

二次

代码语言: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);
}

二次

另见

fopen

opens a file (function)

freopen

open an existing stream with a different name (function)

close

flushes the put area buffer and closes the associated file (public member function of std::basic_filebuf)

c FCLOSE文件

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com