最終更新日時(UTC):
が更新

履歴 編集

function
<sstream>

std::basic_stringbuf::swap(C++11)

void swap(basic_stringbuf& rhs); // (1) C++11

void swap(basic_stringbuf& rhs) noexcept(see below); // (1) C++20

概要

値を交換する。

効果

basic_streambuf<CharT, Traits>::swap(rhs)を呼び出し、modeと内部の文字列バッファをrhsと交換する。

例外

  • C++20 : noexcept(see below)see below は以下と等価である allocator_traits<Allocator>::propagate_on_container_swap::value || allocator_traits<Allocator>::is_always_equal::value

#include <iostream>
#include <sstream>
#include <string>

int main()
{
  std::stringbuf buf1("first");
  std::stringbuf buf2("second");

  buf1.swap(buf2);

  std::cout << buf1.str() << std::endl;
  std::cout << buf2.str() << std::endl;
}

出力

second
first

バージョン

言語

  • C++11

処理系