A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_fstream_swap.htm below:

fstream::swap in C++

C++ Fstream Library - Swap Function Description

It is used to exchanges all internal data between x and *this.

Declaration

Following is the declaration for fstream::swap.

C++11
void swap (basic_fstream& x);
Parameters

x − Another basic_fstream object of the same type (i.e., with the same template parameters charT and traits).

Return Value

none

Exceptions

No-throw guarantee − this member function never throws exceptions.

Data races

It modifies both stream objects (*this and x).

Example

In below example explains about fstream swap function.

#include <fstream>

int main () {
   std::fstream foo;
   std::fstream bar ("test.txt");

   foo.swap(bar);

   foo << "lorem ipsum";

   foo.close();

   return 0;
}

fstream.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4