std::basic_...eam::is_open(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ std::basic_...eam::is_open(3) β€” C++ Standard Libary ✨

Okay bestie, this is the C++ Standard Libary manual page for std::basic_...eam::is_open(3) β€” yes, that's the manual name exactly as the header gives it, and we respect the lore πŸ’….


🌸 NAME 🌸

std::basic_fstream::is_open β€” literally std::basic_fstream::is_open. That's the name section, and it ate πŸ’–.


πŸ¦‹ Synopsis πŸ¦‹

bool is_open() const;

Checks if the file stream has an associated file.

Effectively calls rdbuf()->is_open() ✨.


πŸŽ€ Parameters πŸŽ€

(none) β€” no arguments, no stress, just vibes 🫢.


πŸ’œ Return value πŸ’œ

true if the file stream has an associated file, false otherwise. No cap 🧚.


🌈 Example 🌈

// Run this code

#include <fstream>
#include <iostream>
#include <string>

int main()
{
    std::string filename = "some_file";

    std::fstream fs(filename, std::ios::in);

    std::cout << std::boolalpha;
    std::cout << "fs.is_open() = " << fs.is_open() << '\n';

    if (!fs.is_open())
    {
        fs.clear();
        fs.open(filename, std::ios::out);
        std::cout << "fs.is_open() = " << fs.is_open() << '\n';
    }
}

πŸ’– Possible output πŸ’–

fs.is_open() = false
fs.is_open() = true

πŸ‘‘ Defect reports πŸ‘‘

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. Historical receipts, fr fr:

  • DR LWG 365 β€” applied to C++98; behavior as published: is_open was not declared with const qualifier; correct behavior: declared with const qualifier.

⭐ See also ⭐

  • open β€” opens a file and associates it with the stream (public member function).
  • close β€” closes the associated file (public member function).

Source/version/date tea β˜•: http://cppreference.com β€’ 2024.06.10 β€’ std::basic_...eam::is_open(3). That's the footer, bestie β€” now go check that stream and slay πŸ’–βœ¨

πŸ“¦ where this page comes from