std::basic_filebuf<CharT,Traits>::swap
void swap( std::basic_filebuf& rhs ); | (с C++11) |
Меняет состояние и содержимое *this и rhs.
Параметры
| rhs | - | другой basic_filebuf |
Возвращаемое значение
(нет)
Примечания
Эта функция вызывается автоматически при обмене объектами std::fstream, редко требуется вызывать её напрямую.
Пример
#include <fstream>
#include <iostream>
#include <string>
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
}См. также
|
(C++11) | присваивает объект basic_filebuf (публичный член-функция) |
|
(C++11) | специализирует алгоритм std::swap (функция-шаблон) |
|
(C++11) | меняет местами два потока файлов (публичный член-функция std::basic_fstream<CharT,Traits>) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/io/basic_filebuf/swap