最終更新日時:
が更新

履歴 編集

function template
<fstream>

std::swap (非メンバ関数)(C++11)

namespace std {
  template <class CharT, class Traits>
  void swap(basic_filebuf<CharT, Traits>& x,
            basic_filebuf<CharT, Traits>& y); // (1) C++11
}

概要

2つのbasic_filebufオブジェクトの値を交換する。

効果

x.swap(y)と等価

戻り値

なし

#include <iostream>
#include <fstream>

int main()
{
  {
    std::filebuf out;
    out.open("a.txt", std::ios_base::out);
    out.sputn("A", 1);
  }
  {
    std::filebuf out;
    out.open("b.txt", std::ios_base::out);
    out.sputn("B", 1);
  }

  std::filebuf a;
  a.open("a.txt", std::ios_base::in);

  std::filebuf b;
  b.open("b.txt", std::ios_base::in);

  std::swap(a, b);

  std::cout << static_cast<char>(a.sbumpc()) << std::endl;
  std::cout << static_cast<char>(b.sbumpc()) << std::endl;
}

出力

B
A

バージョン

言語

  • C++11

関連項目