最終更新日時(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++17

概要

値を交換する。

効果

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

例外

  • C++17 : 実装が例外を投げない場合、この関数はnoexceptが指定される。

#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

処理系