#include <iostream>
#include <iomanip>
#include <typeinfo>
#include <bitset>
using std::cout;
using std::endl;
// VC6 数字前、后缀字母 0、0x、U、L、F (即,literal-type 字面类型)
int main(void)
{
cout << "type of '1234567890' is: " << typeid(1234567890).name() << endl;
cout << "type of '1234567890L' is: " << typeid(1234567890L).name() << endl;// long
cout << "type of '1234567890U' is: " << typeid(1234567890U).name() << endl;// unsigned
cout << "type of '1234567890UL' is: " << typeid(1234567890UL).name() << endl;
cout << endl;
// floating point number
cout << "type of '123456789.F' is: " << typeid(123456789.F).name() << endl;// float
cout << "type of '123456789.' is: " << typeid(123456789.).name() << endl;
cout << "type of '123456789.0' is: " << typeid(123456789.0).name() << endl;
cout << "type of '123456789.L' is: " << typeid(123456789.L).name() << endl;// long double
cout << endl;
// pow
cout << "number of '100e-2' is: " << 100e-2 << endl;// 1
cout << "number of '100e+2' is: " << 100e+2 << endl;// 10000
cout << "number of '100e2' is: " << 100e2 << endl;
cout << endl;
// base number
cout << "decimal number of '10' is: " << std::dec << 10 << endl;// decimal literal(base 10)
cout << "decimal number of '010' is: " << std::dec << 010 << endl;// octal literal(base 8)
cout << "decimal number of '0x10' is: " << std::dec << 0x10 << endl;// hex literal(base 16)
cout << "binary number of '0x10' is: " << std::bitset<8>(0x10) << endl;// binary literal(base 2)
cout << endl;
// vc specific:
cout << "type of '123i8' is: " << typeid(123i8).name() << endl;// char
cout << "type of '123i16' is: " << typeid(123i16).name() << endl;// short char
cout << "type of '123i32' is: " << typeid(123i32).name () << endl;// long
cout << "type of '123i64' is: " << typeid(123i64).name() << endl;// long long
cout << "type of '123ui8' is: " << typeid(123ui8).name() << endl;// unsigned char
cout << "type of '123ui16' is: " << typeid(123ui16).name() << endl;// unsigned short char
cout << "type of '123ui64' is: " << typeid(123ui64).name() << endl;// unsigned long long
cout << endl;
return 0;
}
extended integer types
| Type | Suffix in constants | Example | Storage |
|---|---|---|---|
|
__int8 |
i8 |
|
8 bits |
|
unsigned __int8 |
ui8 |
|
8 bits |
|
__int16 |
i16 |
|
16 bits |
|
unsigned __int16 |
ui16 |
|
16 bits |
|
__int32 |
i32 |
|
32 bits |
|
unsigned __int32 |
ui32 |
|
32 bits |
|
__int64 |
i64 |
|
64 bits |
|
unsigned __int64 |
ui64 |
|
64 bits |
本文深入探讨了C++中不同字面量的使用及其对应的数据类型,包括整数、浮点数、指数表示法、基数表示以及特定于VC6的扩展整数类型。通过实际代码示例,展示了如何利用类型别名和字面量后缀来明确指定变量的数据类型。

1471

被折叠的 条评论
为什么被折叠?



