std::basic_filebuf<CharT,Traits>::swap (3) - Linux Manuals
std::basic_filebuf<CharT,Traits>::swap: std::basic_filebuf<CharT,Traits>::swap
Command to display std::basic_filebuf<CharT,Traits>::swap
manual in Linux: $ man 3 std::basic_filebuf<CharT,Traits>::swap
NAME
std::basic_filebuf<CharT,Traits>::swap - std::basic_filebuf<CharT,Traits>::swap
Synopsis
void swap( std::basic_filebuf& rhs ); (since C++11)
Swaps the state and the contents of *this and rhs.
Parameters
rhs - another basic_filebuf
Return value
(none)
Notes
This function is called automatically when swapping std::fstream objects, it is rarely necessary to call it directly.
Example
// Run this code
#include <fstream>
#include <string>
#include <iostream>
int main()
{
std::ifstream fin("test.in"); // read-only
std::ofstream fout("test.out"); // write-only
std::string s;
getline(fin, s);
std::cout << s << '\n'; // outputs the first line of test.in
fin.rdbuf()->swap(*fout.rdbuf()); //swap the underlying buffers
getline(fin, s); // fails: cannot read from a write-only filebuf
std::cout << s << '\n'; // prints empty line
}
See also
operator= assigns a basic_filebuf object
(public member function)
(C++11)
std::swap(std::basic_filebuf) specializes the std::swap algorithm
(function template)
(C++11)
swap swaps two file streams
(public member function of std::basic_fstream<CharT,Traits>)
(C++11)
Pages related to std::basic_filebuf<CharT,Traits>::swap
- std::basic_filebuf<CharT,Traits>::seekoff (3) - std::basic_filebuf<CharT,Traits>::seekoff
- std::basic_filebuf<CharT,Traits>::seekpos (3) - std::basic_filebuf<CharT,Traits>::seekpos
- std::basic_filebuf<CharT,Traits>::setbuf (3) - std::basic_filebuf<CharT,Traits>::setbuf
- std::basic_filebuf<CharT,Traits>::showmanyc (3) - std::basic_filebuf<CharT,Traits>::showmanyc
- std::basic_filebuf<CharT,Traits>::sync (3) - std::basic_filebuf<CharT,Traits>::sync
- std::basic_filebuf<CharT,Traits>::basic_filebuf (3) - std::basic_filebuf<CharT,Traits>::basic_filebuf
- std::basic_filebuf<CharT,Traits>::close (3) - std::basic_filebuf<CharT,Traits>::close
- std::basic_filebuf<CharT,Traits>::imbue (3) - std::basic_filebuf<CharT,Traits>::imbue
- std::basic_filebuf<CharT,Traits>::is_open (3) - std::basic_filebuf<CharT,Traits>::is_open
- std::basic_filebuf<CharT,Traits>::open (3) - std::basic_filebuf<CharT,Traits>::open
- std::basic_filebuf<CharT,Traits>::operator= (3) - std::basic_filebuf<CharT,Traits>::operator=
- std::basic_filebuf<CharT,Traits>::overflow (3) - std::basic_filebuf<CharT,Traits>::overflow
- std::basic_filebuf<CharT,Traits>::pbackfail (3) - std::basic_filebuf<CharT,Traits>::pbackfail
- std::basic_filebuf<CharT,Traits>::uflow (3) - std::basic_filebuf<CharT,Traits>::uflow
- std::basic_filebuf<CharT,Traits>::underflow (3) - std::basic_filebuf<CharT,Traits>::underflow
- std::basic_filebuf<CharT,Traits>::~basic_filebuf (3) - std::basic_filebuf<CharT,Traits>::~basic_filebuf
- std::basic_filebuf (3) - std::basic_filebuf
- std::basic_fstream (3) - std::basic_fstream