I have some C++ code that prints a size_t
:
size_t a;
printf(\"%lu\", a);
I\'d like this to compile without warnings on both 32
The fmt library provides a fast portable (and safe) implementation of printf
including the z
modifier for size_t
:
#include "fmt/printf.h"
size_t a = 42;
int main() {
fmt::printf("%zu", a);
}
In addition to that it supports Python-like format string syntax and captures type information so that you don't have to provide it manually:
fmt::print("{}", a);
It has been tested with major compilers and provides consistent output across platforms.
Disclaimer: I'm the author of this library.