What is the format specifier to print a value of type std::uint64_t
(from <cstdint>
) using functions from the std::printf()
family in C++?
C99 has PRIu64
(from <inttypes.h>
) but it's not entirely clear to me that PRIu64
is valid C++11, although I could find hints that it may be.
Without PRIu64
, and as far as I can tell, there's no single format specifier that will work in all cases:
- On 32-bit platforms,
std::uint64_t
is going to be defined asunsigned long long
and the format specifier will be%llu
. - On 64-bit platforms,
std::uint64_t
is going to be defined asunsigned long
and the format specifier will be%lu
. - However with Visual Studio,
%llu
works in both cases.