std::showpoint / std::noshowpoint
std::showpoint / std::noshowpoint (소수점 표시 조작자)
부동소수점 출력에서 소수점 문자의 무조건 포함 여부를 켜거나 끄는 조작자예요. 입력에는 영향이 없어요.
출처: cppreference
본문
<ios> 헤더에 정의돼 있어요.
// (1)
std::ios_base& showpoint( std::ios_base& str );
// (2)
std::ios_base& noshowpoint( std::ios_base& str );
부동소수점 출력에서 소수점 문자의 무조건 포함 여부를 켜거나 끕니다. 입력에는 영향이 없어요.
-
str.setf(std::ios_base::showpoint)처럼showpoint플래그를 켜요.
-
str.unsetf(std::ios_base::showpoint)처럼showpoint플래그를 꺼요.
I/O 조작자라 out << std::showpoint처럼 쓸 수 있어요.
예제
#include <iostream>
int main()
{
double d = 100.0;
std::cout << d << ' ' // "100"
<< std::showpoint << d << ' ' // "100.000"
<< std::noshowpoint << d << '\n'; // "100"
}