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_free.htm below:

C++ fstream swap Function

C++ Fstream Library - Swap Function Description

It exchanges the values of the fstream objects x and y.

Declaration

Following is the declaration for fstream::swap.

C++11
template <class charT, class traits>
  void swap (basic_fstream<charT,traits>& x, basic_fstream<charT,traits>& y);
Parameters Return Value

none

Exceptions

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

Data races

Both objects, x and y, are modified.

Example

In below example explains about fstream swap function.

#include <fstream>

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

   swap(foo,bar);

   foo << "tutorialspoint";

   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