C++ 檔案流庫 - 賦值運算子函式



描述

它支援 C++ 11 標準的功能版本。它透過移動賦值其成員和基類來獲取右側內容。

宣告

以下是 fstream::operator= 的宣告

C++11

copy (1)	fstream& operator= (const fstream&) = delete;
move (2)	fstream& operator= (fstream&& rhs);

引數

rhs - 另一個 fstream 物件。

返回值

它返回 *this。

異常

無丟擲保證 - 此成員函式從不丟擲異常。

資料競爭

它修改兩個流物件(*this 和 rhs)。

示例

以下示例說明了 fstream 賦值運算子函式。

#include <fstream>

int main () {
   std::fstream foo;
   std::fstream bar ("test.txt");

   swap(foo,bar);

   foo << "tutorialspoint";

   foo.close();

   return 0;
}
fstream.htm
廣告

© . All rights reserved.