赞
踩
注: macosx下要加上 #include <QIODevice> //for macosx
endl替换为Qt::endl;
示例源码:
- #include <QCoreApplication>
- #include <QDebug>
- #include <QTextStream>
- static QTextStream cout (stdout,QIODevice::WriteOnly);
- #include <iostream>
- #include <QtGlobal>
-
- void test()
- {
- qDebug() << "HelloWorld-qdebug";
- cout << "Helloword-QTextStream" <<endl;
- std::cout<<"Helloword-std::cout"<<std::endl;
- }
-
- void test_types()
- {
- qint8 signed_char_type;//signed char 有符号8bit
- qint16 signed_short_type;//signed short 有符号16bit
- qint32 signed_int_type;//signed int 有符号32bit
- qint64 signed_long_long_int_type;//signed long long int 有符号64bit
-
- qDebug() <<"sizeof(qint8)=" <<sizeof (signed_char_type)
- <<"sizeof(qint16)=" <<sizeof (signed_short_type)
- <<"sizeof(qint32)=" <<sizeof(signed_int_type)
- <<"sizeof(qint64)=" <<sizeof (signed_long_long_int_type)<<endl;;
-
- qptrdiff qint32_or_qint64_type;//32位系统 qint32 64位系统 qint64
- qreal double_or_float_type;//默认是double,如果加上-qreal float选项,那么是float
- qintptr same_as_qptrdiff;//32位系统 qint32 64位系统 qint64
- quintptr quint32_or_quint64_type;//32位系统 quint32 64位系统 quint64
- qDebug() <<"sizeof(qptrdiff)=" <<sizeof (qint32_or_qint64_type)
- <<"sizeof(qreal)=" <<sizeof (double_or_float_type)
- <<"sizeof(qintptr)=" <<sizeof(same_as_qptrdiff)
- <<"sizeof(quintptr)=" <<sizeof (quint32_or_quint64_type)<<endl;
-
- quint8 unsigned_char_type;//unsigned char 无符号8bit
- quint16 unsigned_short_type;//unsigned short 无符号16bit
- quint32 unsigned_int_type;//unsigned int 无符号32bit
- quint64 unsigned_long_long_int_type;//unsigned long long int 无符号64bit
- qDebug() <<"sizeof(quint8)=" <<sizeof (unsigned_char_type)
- <<"sizeof(quint16)=" <<sizeof (unsigned_short_type)
- <<"sizeof(quint32)=" <<sizeof(unsigned_int_type)
- <<"sizeof(quint64)=" <<sizeof (unsigned_long_long_int_type)<<endl;
-
- qlonglong same_as_qint64_type;//相当于qint64
- qulonglong same_as_quint64_type;//相当于quint64
- qDebug() <<"sizeof(qlonglong)=" <<sizeof (same_as_qint64_type)
- <<"sizeof(qulonglong)=" <<sizeof (same_as_quint64_type)<<endl;
-
- uchar unsigned_char_type_same_quint8;//unsigned char 无符号8bit
- ushort unsigned_short_type_same_quint16;//unsigned short 无符号16bit
- uint unsigned_int_type_same_quint32;//unsigned int 无符号32bit
- ulong unsigned_long_type;//unsigned long 无符号32bit
- qDebug() <<"sizeof(uchar)=" <<sizeof (unsigned_char_type_same_quint8)
- <<"sizeof(ushort)=" <<sizeof (unsigned_short_type_same_quint16)
- <<"sizeof(uint)=" <<sizeof(unsigned_int_type_same_quint32)
- <<"sizeof(ulong)=" <<sizeof (unsigned_long_type)<<endl;
-
- }
-
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- test();
- test_types();
- return a.exec();
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。