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++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解
- C++中拷贝构造函数的应用详解
- C++中引用(&)的用法与应用实例分析
- C++使用CriticalSection实现线程同步实例
- C++智能指针实例详解
- 解析C++ 浮点数的格式化输出