내 함수는 std::ostream& stream
을 입력 매개 변수로 가져 와서 데이터를 입력하고 stream
을 반환합니다.std :: ios_base :: fmtflags를 저장, 조작 및 복원
stream << "| 1:" << 3.1234567890 << "|" ;
stream << std::endl;
// geting the flags up to now
std::ios_base::fmtflags f = stream.flags();
// setting the flags the way we like it
stream << std::fixed << std::setprecision(9);
stream << "| 2:" << 3.1234567890 << "|" ;
stream.setf(f);
stream << std::endl;
stream << "| 3:" << 3.1234567890 << "|" ;
출력 (surprisengly)입니다 :
| 1:3.12346|
| 2:3.123456789|
| 3:3.123456789|
내가 stream
를 설정하면 나는 기능을 중단으로 함수에서 나는 스트림의 플래그를 조작하지만 복원 할 싶습니다 std::cout
. 분명히 stream.setf(f)
플래그를 복원 할 수 없었습니다. 왜? 그것을하는 올바른 방법은 무엇입니까?
'class std :: ios_base '에'fill '이라는 이름의 멤버가 없습니다. (g ++ --version : g ++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3'). 어떤 의뢰? – arthur
내 실수. 스트림 타입은'std :: basic_ios '이어야한다. (실제 코드는 상대적으로 오래되었고 여기에 typedef를 사용하므로 실제 유형을 보지 못했습니다.) –