fmtlib

fmt: Format C++ Text Safely and Efficiently

{fmt} is a C++ formatting library for producing text and output without relying on C stdio or iostreams. It suits projects that need a type-safe, portable formatting API, with optional compile-time format checks and a header-only mode.

Stars
25.9k
Forks
3.1k
Stars, last 16 days
+21

Our take

Health score

63/100

How it is scored
Activity
67
Community
60
Issues
81
Pull requests
45

+21 stars in the last 16 days

  • Merges more pull requests than 78% of the projects we track
  • More contributors than 77% of the projects we track
  • Slower to merge pull requests than 86% of the projects we track

Overview

{fmt} is a C++ library for formatting values into strings and writing formatted output. It offers an alternative to C stdio and iostreams, with a Python-like format syntax and type-safe argument handling.

It is useful when an application needs consistent formatting across platforms, support for custom types, or control over formatting performance and compile-time checks. The project also implements C++20 std::format and C++23 std::print interfaces.

Key Features

  • Format strings and print output using positional or automatic arguments.
  • Support for compile-time format-string checks in C++20.
  • Format numbers, dates, times, ranges, Unicode text, colors, and user-defined types.
  • Provide a safe printf-style API, including positional arguments.
  • Offer an optional header-only configuration with FMT_HEADER_ONLY.
  • Include tests and continuous fuzzing, according to the project README.

Use Cases

  • C++ application developers can use it to format strings and console output with type-checked arguments.
  • Library authors can add formatting support for custom types through the extension API.
  • Teams targeting multiple platforms can use it for consistent formatting behavior and Unicode support.
  • Performance-sensitive applications can evaluate it as an alternative to iostreams or stdio for formatting workloads.
  • Projects that want to adopt familiar standard formatting interfaces can use its std::format and std::print implementations.

Getting Started

See the README and documentation for installation and build instructions. A basic example is:

#include <fmt/core.h>

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

Considerations

  • This is a C++ library, so using it requires a C++ project and a compatible compiler. The README describes support for older compilers but does not list requirements here.
  • Header-only use is optional. Projects can instead build and link the library.
  • Performance depends on the workload and environment. Consult the linked benchmarks and methodology before choosing it on performance grounds.

Found this useful?

Share it with someone who would like fmt.