std::showpos / std::noshowpos

std::showpos / std::noshowpos (양수 부호 조작자)

비음수 정수 출력에서 '+' 양수 부호 표시 여부를 켜거나 끄는 조작자예요. 입력에는 영향이 없어요.

출처: cppreference

본문

<ios> 헤더에 정의돼 있어요.

// (1)
std::ios_base& showpos( std::ios_base& str );

// (2)
std::ios_base& noshowpos( std::ios_base& str );

비음수 정수 출력에서 '+' 양수 부호 표시 여부를 켜거나 끕니다. 입력에는 영향이 없어요.

    1. str.setf(std::ios_base::showpos)처럼 showpos 플래그를 켜요.
    1. str.unsetf(std::ios_base::showpos)처럼 showpos 플래그를 꺼요.

I/O 조작자라 out << std::showpos처럼 쓸 수 있어요.

예제

#include <iostream>

int main()
{
    std::cout << std::showpos << 42 << ' ' << -1 << ' '   // "+42 -1"
              << std::noshowpos << 42 << '\n';             // "42"
}

더 알아보기 (Learn more)

cppreference