Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::basic_filebuf::swap(3)   C++ Standard Libary  std::basic_filebuf::swap(3)

NAME
       std::basic_filebuf::swap	- std::basic_filebuf::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 ob-
       jects, 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
	  (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>)

http://cppreference.com		  2022.07.31	   std::basic_filebuf::swap(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::wfilebuf::swap&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help