打印 std::uint64_t
类型值的格式说明符是什么? (来自 <cstdint>
)使用来自 std::printf()
的函数C++ 中的家庭?
C99 有 PRIu64
(来自 <inttypes.h>
)但我并不完全清楚 PRIu64
是有效的 C++11,虽然我能找到它可能是的提示。
没有PRIu64
,据我所知,没有一种格式说明符适用于所有情况:
- 在 32 位平台上,
std::uint64_t
将被定义为unsigned long long
并且格式说明符将为%llu
. - 在 64 位平台上,
std::uint64_t
将被定义为unsigned long
并且格式说明符将为%lu
. - 但是对于 Visual Studio,
%llu
在这两种情况下都有效。
最佳答案
PRIu64
仍然是您将在 C++ 中使用的内容。每[cinttypes.syn] PRIu64
[...]
#define PRIuN see below
[...]
The contents and meaning of the header
<cinttypes>
are the same as the C standard library header<inttypes.h>
[...]
因此它存在并且具有与 C ISO/IEC 9899:2011 标准中相同的行为。
关于c++ - 在 C++11 中可移植地打印 std::uint64_t 变量的格式说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56172857/