博客专栏

EEPW首页 > 博客 > error expected beforePRIu64

error expected beforePRIu64

发布人:电子禅石 时间:2022-06-17 来源:工程师 发布文章

error: expected ‘)’ before ‘PRId64’


原来这个宏定义给c用的,C++要用它,就要定义一个__STDC_FORMAT_MACROS宏显示打开它。


c++使用PRID64,需要两步:


包含头文件:<inttypes.h>

定义宏:__STDC_FORMAT_MACROS,可以通过编译时加-D__STDC_FORMAT_MACROS,或者在包含文件之前定义这个宏。



怎么输出uint64_t?出现错误“spurious trailing ‘%’ in format”。
浏览 70关注 0回答 2得****数 0
原文

我编写了一个非常简单的printf uint 64测试代码:

#include <inttypes.h>#include <stdio.h>int main(){
  uint64_t ui64 = 90;
  printf("test uint64_t : %" PRIu64 "\n", ui64);
  return 0;}
复制

我使用ubuntu11.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

原文链接:https://blog.csdn.net/beitiandijun/article/details/19156849


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。



关键词: C++

相关推荐

技术专区

关闭