# std::basic_iostream<CharT,Traits>::swap

> C++ Atlas: `cppatlas.com/w/cpp/io/basic_iostream/swap` | Source: https://en.cppreference.com/w/cpp/io/basic_iostream/swap | Domain: Input/output | Standards: C++11

Exchanges the state with another input/output stream object. Effectively calls basic_istream<CharT,Traits>::swap(other).

## Official Specification Summary (cppreference)

```cpp
protected:
void swap( basic_iostream& other ); // (since C++11)
```

Exchanges the state with another input/output stream object. Effectively calls `basic_istream<CharT,Traits>::swap(other)`.

This member function is protected: it is called by the swap member functions of the derived stream classes `std::basic_stringstream` and `std::basic_fstream`, which know how to correctly swap the associated stream buffers.

### Parameters

- `other` - another stream to exchange the state with

### Return value

`*this`

---
Attribution: content from https://en.cppreference.com/w/cpp/io/basic_iostream/swap (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.