The _format suffix may be used to format string literals similar to Python:

std::stringmessage="{0}{1}{0}"_format("abra","cad");

Other than the placement of the format string on the left of the operator,
_format is functionally identical to fmt::format. In order to use the
literal operators, they must be made visible with the directive
usingnamespacefmt::literals;. Note that this brings in only _a and
_format but nothing else from the fmt namespace.

The library is fully type safe, automatic memory management prevents buffer
overflow, errors in format strings are reported using exceptions or at compile
tim. For example, the code

fmt::format("The answer is {:d}","forty-two");

throws a format_error exception with description “unknown format code ‘d’ for
string”, because the argument "forty-two" is a string while the format code
d only applies to integers, while

format(fmt("The answer is {:d}"),"forty-two");

reports a compile-time error for the same reason on compilers that support
relaxed constexpr.

The following code

fmt::format("Cyrillic letter {}", L'\x42e');

produces a compile-time error because wide character L'\x42e' cannot be
formatted into a narrow string. You can use a wide format string instead:

fmt::format(L"Cyrillic letter {}", L'\x42e');

For comparison, writing a wide character to std::ostream results in
its numeric value being written to the stream (i.e. 1070 instead of letter ‘ю’
which is represented by L'\x42e' if we use Unicode) which is rarely what is
needed.

The library is highly portable and relies only on a small set of C++11 features:

variadic templates

type traits

rvalue references

decltype

trailing return types

deleted functions

These are available since GCC 4.4, Clang 2.9 and MSVC 18.0 (2013). For older
compilers use fmt version 4.x which continues to be
maintained and only requires C++98.

The output of all formatting functions is consistent across platforms. In
particular, formatting a floating-point infinity always gives inf while the
output of printf is platform-dependent in this case. For example,

fmt has a small self-contained code base with the core library consisting of
just three header files and no external dependencies.
A permissive BSD license allows
using the library both in open-source and commercial projects.