您的位置:首页 > 编程语言 > C语言/C++

C++ bool值

2015-06-09 22:02 204 查看
#include <iostream>
using namespace std;
int n;
bool light[65536];
bool test1[10]={1,1,1,1,1,1,1,1,1,1};
bool test2[10]={1,1,1,1,1,1,1,1,1,1};
bool test3[10]={true,true,true,true,true,true,true,true,true,true};
bool test4[10]={false,false,false,false,false,false,false,false,false,false};
int main(){
    test1[0] = ~test1[0];
    test1[1] = ~test1[1];
    test1[2] = ~test1[2];
    test2[0] = test2[0]^1;      /*****bool变量逻辑异或TRUE就取反了**** 这才是正确的***/
    test2[1] = test2[1]^1;
    test2[2] = test2[2]^1;
    test3[0] = ~test3[0];
    test3[1] = ~test3[1];
    test3[2] = ~test3[2];
    test4[0] = ~test4[0];
    test4[1] = ~test4[1];
    test4[2] = ~test4[2];

    for(int i=0;i<10; i++)         /****输出 1 1 1 1 1 1 1 1 1 1 *****wrong**/
        cout<<test1[i]<<" ";
    cout<<endl;
    for(int i=0;i<10; i++)         /****输出 0 0 0 1 1 1 1 1 1 1 *****correct**/
        cout<<test2[i]<<" ";
    cout<<endl;
    for(int i=0;i<10; i++)         /****输出 0 0 0 1 1 1 1 1 1 1 *****wrong**/
        cout<<test2[i]<<" ";
    cout<<endl;
    for(int i=0;i<10; i++)         /****输出 0 0 0 1 1 1 1 1 1 1 *****wrong**/
        cout<<test2[i]<<" ";
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ bool