Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_filebuf<CharT,Traits>::operator=

      From cppreference.com
      <cpp‎ |io‎ |basic filebuf
       
       
       
       
      (1)(since C++11)
      std::basic_filebuf& operator=(conststd::basic_filebuf& rhs)= delete;
      (2)

      Assigns anotherbasic_filebuf object.

      1) First callsclose() to close the associated file, then moves the contents ofrhs into*this: the put and get buffers, the associated file, the locale, the openmode, the is_open flag, and any other state. After the move,rhs is not associated with a file andrhs.is_open()==false.
      2) The copy assignment operator is deleted;basic_filebuf is notCopyAssignable.

      Contents

      [edit]Parameters

      rhs - anotherbasic_filebuf that will be moved from

      [edit]Return value

      *this

      [edit]Example

      Run this code
      #include <cassert>#include <fstream>#include <iostream>#include <string> int main(){std::ofstream{"test.in"}<<"test\n";// writes via a temporary objectstd::ifstream fin("test.in");// read-only streamstd::ofstream fout("test.out");// write-only stream std::string s;std::getline(fin, s);std::cout<<"s = ["<< s<<"]\n";// s contains "test" assert(fout.is_open());*fin.rdbuf()= std::move(*fout.rdbuf());assert(!fout.is_open()); std::getline(fin, s);std::cout<<"s = ["<< s<<"]\n";// s is empty input}

      Output:

      s = [test]s = []

      [edit]See also

      constructs abasic_filebuf object
      (public member function)[edit]
      (C++11)
      swaps twobasic_filebuf objects
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_filebuf/operator%3D&oldid=158235"

      [8]ページ先頭

      ©2009-2025 Movatter.jp