c++ - 我想使用 64 位整数可以采用的完整范围。我如何在 x86 Visual Studio 2008 中执行此操作?

标签 c++ c windows visual-studio visual-studio-2008

我在我的解决方案中包含了 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/

相关文章:

c++ - 如何自动清理 C++ 中的代码?

c++ - 转换非常长的 C++ 字符串文字以满足最大行长度策略

c++ - 繁忙循环与 sleep (0)和暂停指令有什么不同?

c# - 为什么将 DllImport 返回值中的 char[] 替换为 IntPtr 或 StringBuilder 会导致我的程序不再找到正确的入口点?

c - 在终止我的 TCP/IP 连接后使用 POSIX "write"函数会使我的应用程序崩溃 - 为什么?

c++ - 在不直接修改地址的情况下执行地址时引发异常

windows - 可以在 Windows 和 Mac OS 上使用的类似 DB 的 Redis 吗?

c++ - 我怎样才能将文件拖放到哪个 gtkmm 图像小部件

python 3.6 : "AttributeError: ' SimpleQueue' object has no attribute '_poll' "

c - 分配给 const int *