
{fmt}
A C++ library for fast, type-safe text formatting, as a safer alternative to printf and iostreams.
- Stars
- 25.9k
- Forks
- 3.1k
- Licence
- MIT
- Language
- C++
- Last update
- 4 days ago
- Type
- Library
What it is
{fmt} is an open-source C++ library for turning values into formatted text, such as printing to the screen, writing files, or building strings. The README describes it as a fast and safe alternative to C stdio and C++ iostreams. It uses a Python-like format string syntax and is an implementation of C++20 std::format and C++23 std::print.
- Print formatted messages with fmt::print, for example fmt::print("The answer is {}.", 42)
- Format dates and times using the fmt/chrono.h header
- Print containers such as std::vector using the fmt/ranges.h header
- Write formatted output to a file with fmt::output_file
- Print colored and styled text to a terminal using fmt/color.h
Great for
- C++ developers who want a printing or string formatting API that is safer than printf
- Projects that need fast numeric output, such as converting many numbers to text
- Teams that need consistent output across Linux, macOS, and Windows
- Developers who want to format user-defined types with a custom formatter
Not ideal for
- People who do not write C++, since this is a C++ library
- Projects that already use C++20 std::format or C++23 std::print and need nothing extra, since the standard library may cover their needs (the README says {fmt} implements these standards, but does not discuss migration)
- Non-programmers looking for an end-user application
How to get it
- 1
Clone and build from source
You'll need: A C++ compiler with C++11 or later support (exact minimum not confirmed in the truncated README) · CMake (the README does not specify this in the visible portion)
Clone the repository
git clone https://github.com/fmtlib/fmt.git - 2
Run it
- Clone the repository or download the release zip (fmt-12.2.0.zip)
- Add the include directory to your project, or build the library with CMake as described in the full README
- Include <fmt/core.h> in your source file
- Call fmt::print("Hello, world!\n"); and compile
- 3
Get the most out of it
- Use FMT_HEADER_ONLY to avoid building a separate library, as mentioned in the README
- Use the compile API to precompile format strings for faster runtime, as the README notes
- Use fmt/chrono.h and fmt/ranges.h when you need date, time, or container formatting
- Use the printf-compatible API if you are migrating from printf
Downloads
Strengths
- The README reports a broad test suite, continuous fuzzing via OSS-Fuzz, and a compile-time check of format strings
- Has no external dependencies and is available under the permissive MIT license
- The README reports performance advantages over common standard library formatting methods, with benchmarks linked
Trade-offs
- Benchmark results in the README come from the maintainers and specific hardware and compilers; your results may differ
- Adds a library to your build, and the README's compile-time tables show the header-based build is slower to compile than the module build
- The README's pages are truncated here, so details of build options and configuration are not fully visible
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| fmt (this) | 25.9k | Library | intermediate | 4 days ago | C++ developers who want a printing or string formatting API that is safer than printf |
| webview | 14.3k | Library | intermediate | 15 days ago | C or C++ developers who want an HTML-based GUI without bundling a full browser framework |
| JoltPhysics | 12.1k | Library | advanced | 4 days ago | C++ game developers who need a physics engine for rigid bodies and collisions |
| awesome-cpp | 74.2k | Curated list | beginner | 6 days ago | C++ developers looking for a library for a specific task |
| gin | 89.5k | Library | intermediate | 27 days ago | Go developers building REST APIs |
| cpp-httplib | 17k | Library | beginner | 6 days ago | C++ developers who need a simple embedded HTTP server or client without a large framework |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.