François Beaune
François Beaune

Reputation: 4500

Format specifier to portably print std::uint64_t variable in C++11

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:

Upvotes: 5

Views: 4079

Answers (1)

NathanOliver
NathanOliver

Reputation: 180595

PRIu64 is still what you will use in C++. Per [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> [...]

So it exists and has the same behavior that it does in the C ISO/IEC 9899:2011 standard.

Upvotes: 14

Related Questions