Find your next open-source project

Search by name, purpose, or keyword — or paste a GitHub repository URL

fmtlib/fmt

Developer Tools

A fast, type-safe C++ formatting library for replacing printf and iostreams for output and numeric formatting.

25,910
3,095
C++
MIT
13 years old

What it does

{fmt} is an open-source C++ formatting library that offers a fast, type-safe alternative to C stdio and C++ iostreams. It implements C++20 std::format and C++23 std::print, uses a Python-like format syntax, handles positional arguments for localization, and embeds a correct-rounding IEEE 754 floating-point formatter based on Dragonbox. It also ships a safe printf implementation, portable Unicode support, and an extension point for formatting user-defined types.

The library is self-contained with no external dependencies, supports older compilers, and can be used header-only with the FMT_HEADER_ONLY macro. Its format strings can be checked at compile time, so invalid specifiers are reported when the code is compiled rather than at runtime. The API docs, syntax reference, and portability notes live on fmt.dev.

Quick start

You need a C++ compiler and the {fmt} headers and library. The minimal configuration consists of core.h, format.h, and format-inl.h; the project is also available as a module in recent versions. A first program looks like this (example):

#include <fmt/core.h>

int main() {
  fmt::print("Hello, world!\n");
}

Formatting into a string returns a std::string (example):

std::string s = fmt::format("The answer is {}.", 42);
// s == "The answer is 42."

Extra headers enable additional features: include fmt/chrono.h for dates and times, fmt/ranges.h to print containers, fmt/color.h for terminal colors and styles, and fmt/os.h for buffered file output. The documentation covers the API, format syntax, and ported build. Integration into an existing project and the exact build commands are not shown in the README; use the official documentation or your package manager for setup.

Usage constraints

The target is C++ (C++11 or later for the core API; some features depend on newer language modes). Compile-time format string checking requires C++20. Header-only mode trades longer compile times for simpler integration. The library is locale-independent by default, so locale-specific formatting must be opted into. The license is MIT, which permits use in closed-source projects. The project states that it is continuously fuzzed and has an extensive test suite, but compatibility details still vary across platforms and compiler versions.

HotRepo's take

The repository grew from about 23,963 to 25,911 stars across the recorded daily snapshots between September 2 and November 6, 2026, including gains of 955 and 681 on September 3 and 4. On November 6 it appeared on the C++ daily list at position 8, with the overall-language daily rank not recorded. An HN thread from May 2020 drew 44 points and 12 comments, where commenters described fmt as a replacement for both <ostream> and <cstdio> and noted that much of its interface was standardized as C++20 std::format. A 2025 thread about {fmt} v12 mentions 60% faster double formatting, full constexpr, and C++20 modules. These records support the library's long-running adoption, but they are historical snapshots and do not measure current performance or stability.

Written by AI from the project's README, updated . The project's own docs are the source of truth.

Hacker News

Fmt – A Modern Formatting Library
▲ 44 · 12 comments · May 24, 2020
Fmtlib / fmt A modern formatting library
▲ 7 · 0 comments · July 20, 2025
Fmt: A Modern and Lightweight C++ Formatting Library
▲ 3 · 0 comments · August 14, 2024