{fmt} is a C++ formatting library that replaces C's printf and C++ iostreams with a safer, faster API using Python-like format string syntax. It's built for C++ developers who need fast, type-safe output formatting, whether for logging, CLI tools, file writing, or general string construction, and want to avoid the pitfalls of printf format specifiers or the verbosity of iostreams.
The library implements C++20 std::format and C++23 std::print, so code written against {fmt} maps closely to what's becoming standard library behavior. It has no external dependencies and ships as either a compiled library or a header-only configuration via the FMT_HEADER_ONLY macro.
{fmt} fits projects that need frequent string formatting or console/file output and want speed plus compile-time safety: logging libraries, game engines, databases, and server frameworks. It's a good replacement for printf-style code where you want type safety without giving up C-like format specifiers, and a good replacement for iostreams where compile times and code bloat matter. It's also useful as a stepping stone toward std::format/std::print for codebases not yet on a compiler with full C++20/23 support.
It is not the right choice if you're writing a project that has no formatting or text-output needs, or if your toolchain already provides std::format/std::print and you don't need {fmt}'s extras (color output, positional printf, chrono/ranges formatting) or broader compiler compatibility. If minimizing dependencies is a strict requirement and even a small header-only library is unacceptable, iostreams or C stdio remain the fallback.
{fmt} can be added to a project through CMake, as a header-only library, or via package managers. A minimal example using the compiled library:
#include <fmt/base.h>
int main() {
fmt::print("Hello, world!\n");
}
To build and run tests from source, clone the repository and use CMake, per the "Building the library" instructions in the documentation. To run the benchmarks:
$ git clone --recursive https://github.com/fmtlib/format-benchmark.git
$ cd format-benchmark
$ cmake .
$ make speed-test
$ make bloat-test
For header-only use, define the FMT_HEADER_ONLY macro before including the headers, which avoids linking against a separate compiled library. Additional headers like fmt/chrono.h, fmt/ranges.h, fmt/os.h, and fmt/color.h enable formatting for dates/times, containers, file output, and colored terminal text respectively; include only what you need to keep compile times and binary size down. Full setup and integration details, including CMake package config, are in the official documentation at fmt.dev.