我在我的解决方案中包含了 stdint.h 并使用了 uint64_t,但结果不是我想要的。这是我使用的代码。
#include <stdio.h>
#include "./stdint.h"
void main (void)
{
//-- to get the maximum value that the 32-bit integer can take
unsigned int test = 0 ;
test-- ;
//-- to see if the 64-bit integer can take the value that the 32-bit integer can't take
uint64_t test2 = test ;
test2++ ;
printf("%u\n", test) ;
printf("%u\n", test2) ;
while(1) { }
}
这是结果。
4294967295
0
我想使用 64 位整数可以采用的完整范围。我如何在 x86 Visual Studio 2008 中执行此操作?供您引用,我使用的是 32 位 Windows 7。
最佳答案
printf
的%u
格式说明符用于无符号整数。使用 %llu
。
虽然这是 C++,但您也可以使用类型安全的 std::cout
来避免程序员错误:
std::cout << test2;
关于c++ - 我想使用 64 位整数可以采用的完整范围。我如何在 x86 Visual Studio 2008 中执行此操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14858309/