std:: swap (std::basic_ifstream)
From cppreference.net
<
cpp
|
io
|
basic ifstream
|
template
<
class
CharT,
class
Traits
>
void swap ( basic_ifstream < CharT, Traits > & lhs, basic_ifstream < CharT, Traits > & rhs ) ; |
||
std::swap 알고리즘을 std:: basic_ifstream 에 대해 특수화합니다. lhs 의 상태와 rhs 의 상태를 교환합니다. 효과적으로 lhs. swap ( rhs ) 를 호출합니다.
목차 |
매개변수
| lhs, rhs | - | 상태를 교환할 스트림들 |
반환값
(없음)
예외
구현 정의 예외를 던질 수 있습니다.
예제
이 코드 실행
#include <fstream> #include <iostream> #include <string> bool create_stream(std::ifstream& fs) { try { std::string some_name = "/tmp/test_file.txt"; std::ios_base::openmode some_flags = fs.trunc; // | other flags if (std::ifstream ts{some_name, some_flags}; ts.is_open()) { std::swap(ts, fs); // stream objects are not copyable => swap return true; } { catch (...) { std::cout << "Exception!\n"; } return false; } int main() { if (std::ifstream fs; create_stream(fs)) { // use fs stream } }
참고 항목
|
(C++11)
|
두 파일 스트림을 교환합니다
(public member function) |