c/c++中int轉bool判斷

非0即爲真

#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    bool _bv = false;
    _bv = -1;
    if (_bv)
    {
        cout << "-1 is true" << endl;
    }

    _bv = 0;
    if (_bv)
    {
        cout << "0 is true" << endl;
    }
    _bv = 1;
    if (_bv)
    {
        cout << "1 is true" << endl;
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章