C++ 数字前、后缀字母 0、0x、U、L、F

#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

TypeSuffix in constantsExampleStorage

__int8

i8

__int8 c = 127i8;

8 bits

unsigned __int8

ui8

unsigned __int8 c = 240ui8;

8 bits

__int16

i16

__int16 s = 32767i16;

16 bits

unsigned __int16

ui16

unsigned __int16 s = 64532ui16;

16 bits

__int32

i32

__int32 i = 123456789i32;

32 bits

unsigned __int32

ui32

unsigned __int32 i = 223456789ui32;

32 bits

__int64

i64

__int64 big = 12345654321i64;

64 bits

unsigned __int64

ui64

unsigned __int64 hugeInt = 1234567887654321ui64;

64 bits

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值