我写了一个很简单的printf uint64_t的测试代码:
#include <inttypes.h>
#include <stdio.h>
int main()
{
uint64_t ui64 = 90;
printf("test uint64_t : %" PRIu64 "\n", ui64);
return 0;
}
我使用ubuntu 11.10(64位)和gcc 4.6.1版本编译,但是失败了:
main.cpp: In function ‘int main()’:
main.cpp:9:30: error: expected ‘)’ before ‘PRIu64’
main.cpp:9:47: warning: spurious trailing ‘%’ in format [-Wformat]
最佳答案
ISO C99 标准规定,这些宏只有在明确要求时才可以定义。
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
... now PRIu64 will work
关于c++ - 如何打印 uint64_t?失败,出现 : "spurious trailing ‘%’ in format",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8132399/