#include <iostream>
 
using namespace std;
 
int main()
{
    {
        // bool 선언 및 출력
        bool b0 = 0 == 0;
        bool b1 = 0 < 1;
        bool b2 = 0 > 1;
 
        cout << "b0 : " << b0 << endl;
        cout << "b1 : " << b1 << endl;
        cout << "b2 : " << b2 << endl;
    }
    {
        // bool 출력을 true, false로 하도록 변경
        bool b0 = 0 == 0;
        bool b1 = 0 < 1;
        bool b2 = 0 > 1;
 
        cout.setf(ios_base::boolalpha);
        cout << "b0 : " << b0 << endl;
        cout << "b1 : " << b1 << endl;
        cout << "b2 : " << b2 << endl;
    }
    {
        // bool과 if
        bool b0 = 0 == 0;
        bool b1 = 0 < 1;
        bool b2 = 0 > 1;
 
        if (b0)
            cout << "b0" << endl;
        if (b1)
            cout << "b1" << endl;
        if (b2)
            cout << "b2" << endl;
    }
    {
        // bool 에서 정수로 형 변환
        int itrue = true;
        int ifalse = false;
 
        cout << itrue << endl;
        cout << ifalse << endl;
 
 
        // 정수에서 bool로 형 변환
        bool btrue = 100;
        bool bfalse = 0;
 
        cout << btrue << endl;
        cout << bfalse << endl;
    }
}
 
cs

'::public > C++' 카테고리의 다른 글

scanf  (0) 2020.06.29
printf  (0) 2020.06.29
문자형  (0) 2020.06.29
부동 소수점  (0) 2020.06.29
정수형  (0) 2020.06.29

+ Recent posts