| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Public member functions | ||||
(C++11) | ||||
basic_filebuf::swap (C++11) | ||||
(C++26) | ||||
| Protected member functions | ||||
| Non-member functions | ||||
(C++11) |
void swap(std::basic_filebuf& rhs); | (since C++11) | |
Swaps the state and the contents of*this andrhs.
Contents |
| rhs | - | anotherbasic_filebuf |
(none)
This function is called automatically when swappingstd::fstream objects, it is rarely necessary to call it directly.
#include <fstream>#include <iostream>#include <string> int main(){std::ifstream fin("test.in");// read-onlystd::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 filebufstd::cout<< s<<'\n';// prints empty line}
(C++11) | assigns abasic_filebuf object(public member function)[edit] |
| specializes thestd::swap algorithm (function template)[edit] | |
(C++11) | swaps two file streams (public member function of std::basic_fstream<CharT,Traits>)[edit] |