GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::basic_filebuf::swap(3) C++ Standard Libary std::basic_filebuf::swap(3)

std::basic_filebuf::swap - std::basic_filebuf::swap


void swap( std::basic_filebuf& rhs ); (since C++11)


Swaps the state and the contents of *this and rhs.


rhs - another basic_filebuf


(none)


This function is called automatically when swapping std::fstream objects, it is
rarely necessary to call it directly.

// 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
}


operator= assigns a basic_filebuf object
(C++11) (public member function)
std::swap(std::basic_filebuf) specializes the std::swap algorithm
(C++11) (function template)
swap swaps two file streams
(C++11) (public member function of
std::basic_fstream<CharT,Traits>)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.