如何打印uint64_t?失败:“格式为乱码尾随的'%'”; [英] How to printf uint64_t? Fails with: "spurious trailing ‘%’ in format"
本文介绍了如何打印uint64_t?失败:“格式为乱码尾随的'%'”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个非常简单的printf uint64_t测试代码:
I wrote a very simple test code of 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进行编译它,但失败了:
I use ubuntu 11.10 (64 bit) and gcc version 4.6.1 to compile it, but failed:
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标准规定,只有在明确要求时才必须定义这些宏。
The ISO C99 standard specifies that these macros must only be defined if explicitly requested.
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
... now PRIu64 will work
这篇关于如何打印uint64_t?失败:“格式为乱码尾随的'%'”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文