C++
[C++] boolalpha 사용해서 true/false 출력하기
kugnuoy
2024. 1. 16. 13:01
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 출력
}