在线文档教程
C++
输入/输出 | Input/output

std::basic_filebuf::is_open

性病:基本[医]filebuf::is[医]开着的营业的

bool is_open() const;

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

参数

%280%29

返回值

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

注记

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

二次

#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'; }

二次

产出:

二次

direct call: true through streambuf: true through fstream: true

二次

另见

openopens a file and configures it as the associated character sequence (public member function)
closeflushes the put area buffer and closes the associated file (public member function)

© cppreference.com

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

http://en.cppreference.com/w/cpp/io/basic[医]filebuf/is[医]开着的营业的