std::basic_filebuf<CharT,Traits>:: swap
From cppreference.net
<
cpp
|
io
|
basic filebuf
|
void
swap
(
std::
basic_filebuf
&
rhs
)
;
|
(C++11 이후) | |
* this 와 rhs 의 상태와 내용을 교환합니다.
목차 |
매개변수
| rhs | - |
another
basic_filebuf
|
반환값
(없음)
참고 사항
이 함수는 std::fstream 객체를 교환할 때 자동으로 호출되므로, 직접 호출할 필요는 거의 없습니다.
예제
이 코드 실행
#include <fstream> #include <iostream> #include <string> int main() { std::ifstream fin("test.in"); // 읽기 전용 std::ofstream fout("test.out"); // 쓰기 전용 std::string s; getline(fin, s); std::cout << s << '\n'; // test.in의 첫 번째 줄 출력 fin.rdbuf()->swap(*fout.rdbuf()); // 기본 버퍼 교환 getline(fin, s); // 실패: 쓰기 전용 filebuf에서 읽을 수 없음 std::cout << s << '\n'; // 빈 줄 출력 }
참고 항목
|
(C++11)
|
basic_filebuf
객체를 할당함
(public member function) |
|
(C++11)
|
std::swap
알고리즘을 특수화함
(function template) |
|
(C++11)
|
두 파일 스트림을 교환함
(
std::basic_fstream<CharT,Traits>
의
public member function)
|