std::basic_filebuf<CharT,Traits>::is_open
From cppreference.com
< cpp | io | basic filebuf
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Input/output library
Print functions (C++23)
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;
Returns true if the most recent call to open() succeeded and there has been no call to close() since then.
Contents
[edit] Parameters
(none)
[edit] Return value
true if the associated file is open, false otherwise.
[edit] Notes
This function is typically called by std::basic_fstream::is_open() .
[edit] Example
Run this code
#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'; }
Output:
direct call: true through streambuf: true through fstream: true