C语言 如何在 gcc 中打印 UINT64_t?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30092872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to print UINT64_t in gcc?
提问by Ramakant
Why this code is not working?
为什么这段代码不起作用?
#include <stdio.h>
main()
{
UINT64_t ram = 90;
printf("%d""\n", ram);
}
I got the Following errors:
我收到以下错误:
In function \u2018main\u2019
error: \u2018UINT64_t\u2019 undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: expected \u2018;\u2019 before \u2018ram\u2019
回答by niyasc
uint64_tis defined in Standard Integer Type header file. ie, stdint.h.
So first include stdint.hin your program.
uint64_t在标准整数类型头文件中定义。即,stdint.h。所以首先包括stdint.h在你的程序中。
Then you can use format specifier "%"PRIu64to print your value: i.e.
然后您可以使用格式说明符"%"PRIu64打印您的值:即
printf("%" PRIu64 "\n", ram);
You can refer this question also How to print a int64_t type in C
您也可以参考这个问题How to print a int64_t type in C
回答by xanatos
Full working example: http://ideone.com/ttjEOB
完整的工作示例:http: //ideone.com/ttjEOB
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
int main()
{
uint64_t ram = 90;
printf("%" PRIu64 "\n", ram);
}
You forgot some headers, wrote incorrectly uint64_tand can't use %dwith uint64_t
你忘了一些头,写了不正确uint64_t且不能使用%d与uint64_t
回答by ckolivas
Add:
添加:
#include <inttypes.h>
And use PRIu64 (outside of quotation marks like so):
并使用 PRIu64(像这样在引号之外):
printf("%"PRIu64"\n", ram);

