std::basic_filebuf::close(3)
π NAME π
okay bestie, welcome to the manual page for std::basic_filebuf::close(3) from the C++ Standard Libary β yes, that's the spelling in the header and we're keeping it, no notes πβ¨
std::basic_filebuf::close β literally the name, and also std::basic_filebuf::close again. It's giving "the NAME line said it twice and we respect the hustle" π
β¨ Synopsis β¨
std::basic_filebuf<CharT, Traits>* close();
So here's the tea: if a put area exists (like when the file was opened for writing), it first calls overflow(Traits::eof()) to write all pending output to the file, including any unshift sequences. π«Ά
If the most recently called function out of underflow(), overflow(), seekpos(), and seekoff() was overflow(), then it calls std::codecvt::unshift(), maybe multiple times, to determine the unshift sequence according to the imbued locale, and writes that sequence to the file with overflow(Traits::eof()). β¨
Then it closes the file as if by calling std::fclose(), regardless of whether any of the preceding calls succeeded or failed. no cap.
If any of the function calls made, including the call to std::fclose(), fails, it returns a null pointer. If any of the function calls made throws an exception, the exception is caught and rethrown after closing the file. If the file is already closed, it returns a null pointer right away. π
In any case, it updates the private member variable that is accessed by is_open(). π
π Parameters π
- (none) β literally none, bestie. π
πΈ Return value πΈ
thison success- a null pointer on failure
π¦ Notes π¦
close() is typically called through the destructor of std::basic_filebuf (which, in turn, is typically called by the destructor of std::basic_fstream). so it's kind of a background main character, yk? π
β Example β
This section is incomplete Reason: no example π
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. π
- DR
LWG 443, applied to C++98 β behavior as published: the file was written usingoverflow(EOF); correct behavior: changed tooverflow(Traits::eof()). π₯ - DR
LWG 622, applied to C++98 β behavior as published: it was unclear how to handle the exception thrown during closing; correct behavior: it is rethrown after closing the file. π
π See also π
is_openβ checks if the associated file is open (public member function)destructorβ destructs abasic_filebufobject and closes the file if it is open[virtual](virtual public member function)
π·οΈ Category π·οΈ
* Todo no example
source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::basic_filebuf::close(3) β bye bestie, mwah ππ
π¦ 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