0 c c++ windows visual-studio-2008 visual-studio
我在我的解决方案中包含了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) { }
}
Run Code Online (Sandbox Code Playgroud)
这是结果.
4294967295
0
Run Code Online (Sandbox Code Playgroud)
我想使用64位整数可以采用的全范围.我怎么能在x86 Visual Studio 2008中做到这一点?为了您的信息,我使用的是32位Windows 7.
该%u格式说明的printf是无符号整数.使用%llu.
既然这是C++,你也可以使用类型安全std::cout来避免程序员错误:
std::cout << test2;
Run Code Online (Sandbox Code Playgroud)