std::basic_fstream::close(3)
π NAME π
Okay so this is std::basic_fstream::close(3) from the C++ Standard Libary β yes, thatβs the manual name, bestie, weβre folding it in right here at the top instead of copying the whole header line. The name is literally std::basic_fstream::close, and the page is also std::basic_fstream::close. Iconic consistency, no notes. π
β¨ Synopsis β¨
void close();
Closes the associated file.
Effectively calls rdbuf()->close(). If an error occurs during operation, setstate(failbit) is called.
π«Ά Translation: itβs doing the stream-buffer close thing, and if something goes wrong it flips the fail state. That part matters, bestie.
πΈ Parameters πΈ
(none)
Likeβ¦ zero parameters. She takes no arguments and she does not need any. Lowkey main character energy. π
π Return value π
(none)
No return value. Itβs giving βI do the thing, I donβt hand you a souvenir.β β¨
π¦ Notes π¦
This function is called by the destructor of basic_fstream when the stream object goes out of scope and is not usually invoked directly.
So fr fr: the destructor handles this when the stream object leaves scope, and calling it directly is not usually the move. Let the destructor do its little cleanup moment. π
π₯ Example π₯
// Run this code β go off, bestie:
#include <fstream>
#include <iostream>
#include <string>
int main()
{
std::fstream f1("example1", std::ios::out),
f2("example2", std::ios::out),
f3("example3", std::ios::out);
std::cout << std::boolalpha
<< f1.is_open() << '\n'
<< f2.is_open() << '\n'
<< f3.is_open() << '\n';
f1.close();
f2.close();
std::cout << f1.is_open() << '\n'
<< f2.is_open() << '\n'
<< f3.is_open() << '\n';
}
Possible output:
true
true
true
false
false
true
Not the true true true turning into false false true arc π β f1 and f2 got closed, and f3 is still open and thriving. Slay. π
β See also β
is_openβ checks if the stream has an associated file (public member function)openβ opens a file and associates it with the stream (public member function)closeβ flushes the put area buffer and closes the associated file (public member function ofstd::basic_filebuf<CharT,Traits>)
Source/version and date sign-off, because we keep the footer facts cute and complete: http://cppreference.com, 2024.06.10, std::basic_fstream::close(3) β mwah, bestie ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms