Namespaces
Variants
Views
Actions

std::basic_filebuf::is_open

From cppreference.com
< cpp‎ | io‎ | basic filebuf
Revision as of 21:42, 2 November 2012 by P12bot (Talk | contribs)

bool is_open() const;

Returns true if the most recent call to Template:rlpf succeeded and there has been no call to Template:rlpf since then.

Contents

Parameters

(none)

Return value

true if the associated file is open, false otherwise.

Notes

This function is typically called by std::basic_fstream::is_open.

Example

#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

See also

Template:cpp/io/basic filebuf/dcl list openTemplate:cpp/io/basic filebuf/dcl list close