名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | io‎ | basic filebuf
 
 
 
 
(1) (C++11 起)
std::basic_filebuf& operator=( const std::basic_filebuf& rhs ) = delete;
(2)

賦值另一個 basic_filebuf 物件。

1) 首先呼叫 close() 關閉關聯檔案,然後將 rhs 的內容移動到 *this 中:包括輸入和輸出緩衝區、關聯檔案、區域設定、開啟模式、is_open 標誌以及任何其他狀態。移動後,rhs 不再與檔案關聯,並且 rhs.is_open() == false
2) 複製賦值運算子已被刪除;basic_filebuf 不可 CopyAssignable

目錄

[編輯] 引數

rhs - 另一個將被移動的 basic_filebuf

[編輯] 返回值

*this

[編輯] 示例

#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
 
int main()
{
    std::ofstream{"test.in"} << "test\n"; // writes via a temporary object
    std::ifstream fin("test.in"); // read-only stream
    std::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
}

輸出

s = [test]
s = []

[編輯] 參閱

構造一個 basic_filebuf 物件
(public member function) [編輯]
(C++11)
交換兩個 basic_filebuf 物件
(public member function) [編輯]