VC中__int64的用法

VCVC6.0的64位整数分别叫做__int64与unsigned __int64,其范围分别是[-2^63, 2^63)与[0,2^64),即-922337203685 4775808~922337203685 4775807(10^19)与0~18446744073709551615(约1800亿亿)(10^20)。对64位整数的运算与32位整数基本相同,都支持四则运算与 位运算等。当进行64位与32位的混合运算时,32位整数会被隐式转换成64位整数。但是,VC的输入输出与__int64的兼容就不是很好了,如果你写下这样一段代码:
1 __int64 a;
2 cin >> a;
3 cout << a;
那么,在第2行会收到“error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '__int64' (or there is no acceptable conversion)”的错误;在第3行会收到“error C2593: 'operator <<' is ambiguous”的错误。那是不是就不能进行输入输出呢?当然不是,你可以使用C的写法:
scanf("%I64d",&a);
printf("%I64d",a);
就可以正确输入输出了。当使用unsigned __int64时,把 "I64d"改为 "I64u"就可以了。
原文地址:https://www.cnblogs.com/snake-hand/p/3190006.html