bool 변수에 true 혹은 false 값을 저장해도
cout 으로 출력할 때는 1 혹은 0 으로 출력한다.
따라서 아래 코드와 같이 boolalpha를 사용해 bool 값을 true/false 로 출력할 수 있다.
noboolalpha를 사용해 다시 1/0으로 출력할 수도 있다.
#include "iostream"
#include <cstdint>
using namespace std;
int main(void) {
bool b = true;
cout << b << endl;
----------------------
1 출력
cout << boolalpha;
cout << b << endl;
----------------------
true 출력
cout << noboolalpha;
cout << b << endl;
----------------------
1 출력
}
'C++' 카테고리의 다른 글
[C++] escape sequences (0) | 2024.01.16 |
---|---|
[C++] Type Casting (0) | 2024.01.16 |
[C++] 부동 소수점 숫자의 정밀도(Precision) (0) | 2024.01.16 |
[C++] 고정 너비 변수 (Fixed Width Integers) (0) | 2024.01.16 |
[C++] 조건부 컴파일(Conditional compilation) (0) | 2024.01.15 |