Skip to content

Latest commit

 

History

History
76 lines (59 loc) · 1.44 KB

File metadata and controls

76 lines (59 loc) · 1.44 KB

swap

  • fstream[meta header]
  • std[meta namespace]
  • basic_filebuf[meta class]
  • function[meta id-type]
  • cpp11[meta cpp]
void swap(basic_filebuf& rhs); // (1) C++11

概要

rhsとの間で、値を交換する。

効果

*thisrhsの状態を交換する。開いているファイル、オープンモード、ロケール、バッファのいずれもが交換対象である。

戻り値

なし

#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);

  a.swap(b);

  std::cout << static_cast<char>(a.sbumpc()) << std::endl;
  std::cout << static_cast<char>(b.sbumpc()) << std::endl;
}
  • std::filebuf[link /reference/fstream/basic_filebuf.md]
  • a.swap[color ff0000]
  • out.open[link open.md]
  • a.open[link open.md]
  • b.open[link open.md]
  • out.sputn[link /reference/streambuf/basic_streambuf/sputn.md]
  • a.sbumpc()[link /reference/streambuf/basic_streambuf/sbumpc.md]
  • b.sbumpc()[link /reference/streambuf/basic_streambuf/sbumpc.md]

出力

B
A

バージョン

言語

  • C++11

関連項目