Namespaces
Variants

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

From cppreference.net
(1) (C++11 이후)
std:: basic_filebuf & operator = ( const std:: basic_filebuf & rhs ) = delete ;
(2)

다른 basic_filebuf 객체를 할당합니다.

1) 먼저 연결된 파일을 닫기 위해 close() 를 호출한 다음, rhs 의 내용을 * this 로 이동합니다: put 및 get 버퍼, 연결된 파일, 로케일, 열기 모드, 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"; // 임시 객체를 통해 기록
    std::ifstream fin("test.in"); // 읽기 전용 스트림
    std::ofstream fout("test.out"); // 쓰기 전용 스트림
    std::string s;
    std::getline(fin, s);
    std::cout << "s = [" << s << "]\n"; // s는 "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는 빈 입력
}

출력:

s = [test]
s = []

참고 항목

basic_filebuf 객체를 생성합니다
(public member function)
(C++11)
두 개의 basic_filebuf 객체를 교환합니다
(public member function)