std::basic_filebuf<CharT,Traits>:: is_open
From cppreference.net
<
cpp
|
io
|
basic filebuf
C++
Input/output library
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
std::basic_filebuf
| Public member functions | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
basic_filebuf::is_open
|
||||
| Protected member functions | ||||
| Non-member functions | ||||
|
(C++11)
|
|
bool
is_open
(
)
const
;
|
||
若最近一次对 open() 的调用成功,且此后未调用过 close() ,则返回 true 。
目录 |
参数
(无)
返回值
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
参见
|
打开文件并将其配置为关联的字符序列
(公开成员函数) |
|
|
刷新输出区缓冲区并关闭关联文件
(公开成员函数) |