Skip to content
Advertisement

what is the format specifier for atomic datatype in C++?

I am using Ubuntu virtual box and writing a project in C++. I am unable to put a format specifier for atomic<uint64_t> datatype in C++.

Advertisement

Answer

Use .load() to get uint64_t out of the atomic, then print it as a regular uint64_t using PRIu64:

#include <atomic>
#include <cinttypes>
#include <cstdint>
#include <cstdio>

int main()
{
    std::atomic<std::uint64_t> x = 42;
    std::printf("x = %" PRIu64 "n", x.load());
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement