Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_filebuf<CharT,Traits>::swap

      From cppreference.com
      <cpp‎ |io‎ |basic filebuf
       
       
       
       
      void swap(std::basic_filebuf& rhs);
      (since C++11)

      Swaps the state and the contents of*this andrhs.

      Contents

      [edit]Parameters

      rhs - anotherbasic_filebuf

      [edit]Return value

      (none)

      [edit]Notes

      This function is called automatically when swappingstd::fstream objects, it is rarely necessary to call it directly.

      [edit]Example

      Run this code
      #include <fstream>#include <iostream>#include <string> int main(){std::ifstream fin("test.in");// read-onlystd::ofstream fout("test.out");// write-only std::string s;    getline(fin, s);std::cout<< s<<'\n';// outputs the first line of test.in     fin.rdbuf()->swap(*fout.rdbuf());//swap the underlying buffers     getline(fin, s);// fails: cannot read from a write-only filebufstd::cout<< s<<'\n';// prints empty line}

      [edit]See also

      (C++11)
      assigns abasic_filebuf object
      (public member function)[edit]
      specializes thestd::swap algorithm
      (function template)[edit]
      (C++11)
      swaps two file streams
      (public member function ofstd::basic_fstream<CharT,Traits>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_filebuf/swap&oldid=158143"

      [8]ページ先頭

      ©2009-2025 Movatter.jp