std::swap(s...c_ofstream)(3)
β¨ NAME β¨
okay bestie, this is the page for std::swap(std::basic_ofstream) from the C++ Standard Libary manual β yes, thatβs the manual name, spelling and all, and Iβm not touching it π
. The page title is literally std::swap(std::basic_ofstream), and the NAME line is:
std::swap(std::basic_ofstream) - std::swap(std::basic_ofstream)
πΈ Synopsis πΈ
template< class CharT, class Traits >
void swap( basic_ofstream<CharT, Traits>& lhs, basic_ofstream<CharT,
Traits>& rhs
);
This specializes the std::swap algorithm for std::basic_ofstream. It exchanges the state of lhs with that of rhs. Effectively, it calls lhs.swap(rhs). slay.
π Parameters π
lhs,rhsβ streams whose state to swap π«Ά
π¦ Return value π¦
(none) β thatβs it, bestie, nothing comes back π
β Exceptions β
May throw implementation-defined exceptions.
π₯ Example π₯
the example literally starts with // Run this code, so hereβs the whole thing exactly as it appears:
// Run this code
#include <fstream>
#include <iostream>
#include <string>
bool create_stream(std::ofstream& fs)
{
try
{
std::string some_name = "/tmp/test_file.txt";
std::ios_base::openmode some_flags = fs.trunc; // | other flags
if (std::ofstream ts{some_name, some_flags}; ts.is_open())
{
std::swap(ts, fs); // stream objects are not copyable => swap
return true;
}
}
catch (...)
{
std::cout << "Exception!\n";
}
return false;
}
int main()
{
if (std::ofstream fs; create_stream(fs))
{
// use fs stream
}
}
π See also π
swapβ swaps two file streams(C++11)(public member function)β¨
π thatβs the whole page, bestie β brought to you by http://cppreference.com, dated 2024.06.10, with the footer title std::swap(s...c_ofstream)(3). periodt π
π¦ 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