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

std::basic_filebuf::is_open

bool is_open() const;

?

?

回报true如果最近的电话open()成功了,没有人呼吁close()从那以后。

参数

%280%29

返回值

true如果相关文件打开,false否则。

注记

此函数通常由std::basic_fstream::is_open()...

二次

代码语言:javascript
复制
#include <fstream>
#include <iostream>
 
int main()
{
    std::ifstream fs("test.txt");
    std::filebuf fb;
    fb.open("test.txt", std::ios_base::in);
    std::cout << std::boolalpha
              << "direct call: " << fb.is_open() << '\n'
              << "through streambuf: " << fs.rdbuf()->is_open() << '\n'
              << "through fstream: " << fs.is_open() << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
direct call: true
through streambuf: true
through fstream: true

二次

另见

open

opens a file and configures it as the associated character sequence (public member function)

close

flushes the put area buffer and closes the associated file (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com