std::basic_ios<CharT,Traits>:: copyfmt
|
basic_ios
&
copyfmt
(
const
basic_ios
&
other
)
;
|
||
만약 other 가 * this 와 동일한 객체를 참조하면, 아무런 효과도 없습니다. 그렇지 않으면, 스트림 other 의 상태를 * this 로 복사합니다. 이는 다음 순서로 수행됩니다:
iword
와
pword
포인터 자체는 제외), 콜백들, 그리고 연결된 스트림의 복사본을 만듭니다.
목차 |
매개변수
| other | - | 다른 소스로 사용할 스트림 |
반환값
* this
참고 사항
콜백을 통한 두 번째 패스는 std::ios_base::pword 내 포인터들이 가리키는 사용자 정의 객체들을 딥 카피하는 데 사용될 수 있습니다.
copyfmt()
는 스트림의 상태를 저장하고 복원하는 데 사용될 수 있습니다. Boost는 동일한 목적으로 더 세분화된
I/O 상태 저장기
라이브러리를 제공합니다.
예제
std::ofstream
객체 "out"이 서식 지정,
tie()
등을 포함하여
std::cout
과 완전히 동일하게 동작하도록 만듭니다.
#include <bitset> #include <climits> #include <fstream> #include <iostream> int main() { std::ofstream out; out.copyfmt(std::cout); // copy everything except rdstate and rdbuf out.clear(std::cout.rdstate()); // copy rdstate out.basic_ios<char>::rdbuf(std::cout.rdbuf()); // share the buffer out << "Hello, world\n"; auto bin = [](std::ios_base::fmtflags f) { return std::bitset<sizeof(std::ios_base::fmtflags) * CHAR_BIT> { static_cast<unsigned long long>(f) }; }; std::ofstream out2; std::cout << "1) out2.flags(): " << bin(out2.flags()) << '\n'; std::cout << "2) cout.flags(): " << bin(std::cout.flags()) << '\n'; std::cout.setf(std::ios::hex | std::ios::fixed | std::ios::boolalpha); std::cout << "3) cout.flags(): " << bin(std::cout.flags()) << '\n'; out2.copyfmt(std::cout); // copy everything except rdstate and rdbuf std::cout << "4) out2.flags(): " << bin(out2.flags()) << '\n'; }
가능한 출력:
Hello, world 1) out2.flags(): 00000000000000000001000000000010 2) cout.flags(): 00000000000000000001000000000010 3) cout.flags(): 00000000000000000001000000001111 4) out2.flags(): 00000000000000000001000000001111
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 256 | C++98 |
3단계에서 등록된 콜백을
정의되지 않은 이벤트 타입
copy_event
로 호출함
|
다음으로 수정됨
copyfmt_event |
| LWG 292 | C++98 |
other
가
*
this
와 동일한 객체를 참조할 경우,
멤버 객체들이 여전히 복사되고 등록된 콜백들이 여전히 호출됨 |
이 경우
아무 작업도 수행하지 않음 |