ar进行信息输入和输入的一个细节问题
来源:互联网 发布:手机书法练字软件 编辑:程序博客网 时间:2024/06/07 05:03
在使用ar<<和ar>>对数据进行输入输出时,CArchive::operator >> 对bool型没重载, 必须换成BOOL 。我在一个程序里曾碰到这样的问题,声明一个bool型数组,然后想将其信息输入:
bool m_bColor[64];
...
for(i=0; i<64; i++)
{
ar<<m_bColor[i]; //信息输入
}
但编译后出现如下错误:error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'bool' (or there is no acceptable conversion)。
将bool换成BOOL问题得以解决。
那么,bool和BOOL到底有什么区别呢?在查MSDN时CArchive::operator <<时:
CArchive::operator <<
This operator stores the indicated object or primitive type to the archive.
friend CArchive& operator <<( CArchive& ar, const CObject* pOb );
throw( CArchiveException, CFileException );
CArchive& operator <<( BYTE by );
throw( CArchiveException, CFileException );
CArchive& operator <<( WORD w );
throw( CArchiveException, CFileException );
CArchive& operator <<( LONG l );
throw( CArchiveException, CFileException );
CArchive& operator <<( DWORD dw );
throw( CArchiveException, CFileException );
CArchive& operator <<( float f );
throw( CArchiveException, CFileException );
CArchive& operator <<( double d );
throw( CArchiveException, CFileException );
发现并没有单独对BOOL和bool类型变量重载。事实上,BOOL就是int 型。
bool在C++里是占用1字节,而BOOL是int类型,int类型的大小是视具体环境而定的;所以来说:false/true只占用1个字节,而TRUE/FALSE视具体环境而言,以下是BOOL在windef.h中的定义:typedef int BOOL;
false/true是标准C++语言里新增的关键字,而FALSE/TRUE是通过#define,这要用途是解决程序在C与C++中环境的差异,以下是FALSE/TRUE在windef.h的定义:
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
也就是说FALSE/TRUE是int类型,而false/true是bool类型;所以两者不一样的,只不过我们在使用中没有这种感觉,因为C++会帮你做隐式转换。
- ar进行信息输入和输入的一个细节问题
- 输入函数的细节
- 统计设计的问题和输入一个字符串的问题
- 一个字符输入的问题
- 将一个输入的字符串进行逆序
- cin和getline输入的一个小问题
- 笔记——字符串输入的细节问题
- qt5输入的一些细节
- 输入学生信息的!
- 学生信息的输入
- 关于function输入的一个奇怪问题
- 一个关于C语言输入的问题
- 一个关于C语言输入的问题
- 一个关于输入流出错的问题
- 关于getline输入的一个小问题
- 用输入的字符串和任意一个数字进行运算,可以判断
- c之关于输入 scanf 和其他输入的问题
- c之关于输入 scanf 和其他输入的问题
- Flash OBJECT和EMBED标签
- ue语法着色文件
- wait,notify,notifyAll函数分析
- Get Things Done--我的时间管理
- 隔岸观火
- ar进行信息输入和输入的一个细节问题
- C#中常用函数总结
- 我的智囊团(SSH)_mldn
- CSpinButtonCtrl::GetPos()和GetPos32( )两个函数的用法
- JavaScript脚本
- 关于Oracle中不能扩展Undo表空间的问题
- ASP.NET 2.0 本地化技术之研究(一)
- j2sdk_5_0.exe的使用
- ASP.NET 2.0 本地化技术之研究(二)