# {fmt}: A Modern, Fast, and Safe Formatting Library for C++

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Source: osrepos.com
Repository profile: https://osrepos.com/repo/fmtlib-fmt
Generated for open source discovery and AI-assisted research.

{fmt} is a powerful open-source formatting library for C++ that offers a fast and type-safe alternative to traditional C stdio and C++ iostreams. It provides a modern API, implements C++20 std::format and C++23 std::print, and boasts superior performance and compile-time safety. With its extensive features and broad adoption, {fmt} is an excellent choice for modern C++ development.

GitHub: https://github.com/fmtlib/fmt
OSRepos URL: https://osrepos.com/repo/fmtlib-fmt

## Summary

{fmt} is a powerful open-source formatting library for C++ that offers a fast and type-safe alternative to traditional C stdio and C++ iostreams. It provides a modern API, implements C++20 std::format and C++23 std::print, and boasts superior performance and compile-time safety. With its extensive features and broad adoption, {fmt} is an excellent choice for modern C++ development.

## Topics

- c-plus-plus
- cpp
- formatting
- performance
- cross-platform
- unicode
- library
- utility

## Repository Information

Last analyzed by OSRepos: Tue Nov 18 2025 20:01:30 GMT+0000 (Western European Standard Time)
Detail views: 5
GitHub clicks: 4

## Safety Notice

OSRepos shares public repositories for knowledge and discovery only. Review source code, dependencies, licenses, and security implications before running or installing anything.

## Content

## Introduction
`{fmt}` is a highly acclaimed open-source formatting library for C++, designed to be a fast, safe, and modern alternative to `printf` and C++ iostreams. With over 22,898 stars on GitHub, it's a widely adopted solution for robust and efficient string formatting. The library offers a Python-like format string syntax, supports positional arguments for localization, and provides an implementation of the C++20 `std::format` and C++23 `std::print` proposals. It emphasizes performance, type-safety, and portability, making it an essential tool for contemporary C++ projects.

## Installation
To integrate `{fmt}` into your project, you typically need to build it from source or include it as a header-only library. The recommended approach involves using a build system like CMake.

For detailed instructions on how to build the library from source, integrate it into your project, or use its header-only configuration, please refer to the official documentation:
[https://fmt.dev/latest/get-started/#building-from-source](https://fmt.dev/latest/get-started/#building-from-source){:target="_blank"}

## Examples
`{fmt}` provides a versatile and intuitive API for various formatting tasks. Here are a few examples demonstrating its capabilities:

**Print to stdout**
c++
#include <fmt/base.h>

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


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


**Format a string using positional arguments**
c++
std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
// s == "I'd rather be happy than right."


**Print dates and times**
c++
#include <fmt/chrono.h>
#include <chrono>

int main() {
  auto now = std::chrono::system_clock::now();
  fmt::print("Date and time: {}\n", now);
  fmt::print("Time: {:%H:%M}\n", now);
}


**Print a container**
c++
#include <vector>
#include <fmt/ranges.h>

int main() {
  std::vector<int> v = {1, 2, 3};
  fmt::print("{}\n", v);
}


## Why Use {fmt}?
`{fmt}` addresses several shortcomings of existing C++ formatting solutions, offering compelling advantages:

*   **Performance**: It is significantly faster than `printf`, C++ iostreams, `to_string`, and `to_chars` in many benchmarks, especially for floating-point and integer formatting.
*   **Type-Safety**: Unlike `printf`, `{fmt}` is fully type-safe, preventing common errors like format string mismatches at compile time (with C++20).
*   **Modern API**: It offers a clean, intuitive API similar to Python's `str.format`, supporting positional arguments crucial for internationalization.
*   **C++20/C++23 Compatibility**: `{fmt}` provides an implementation of `std::format` and `std::print`, allowing for a smooth transition to future C++ standards.
*   **Extensibility**: Easily extendable to support user-defined types.
*   **Small Code Size**: Minimal configuration requires only three files, leading to small compiled code size and fast compile times, comparable to `printf`.
*   **Portability**: Consistent output across various platforms and support for older compilers.
*   **Reliability**: Extensively tested and continuously fuzzed for robustness.
*   **Ease of Use**: Self-contained, no external dependencies, and distributed under the permissive MIT license.

Many notable projects, including Apple's FoundationDB, Aseprite, Blizzard Battle.net, ClickHouse, MongoDB, PyTorch, and Windows Terminal, rely on `{fmt}` for their formatting needs, underscoring its reliability and efficiency.

## Links
*   **GitHub Repository**: [https://github.com/fmtlib/fmt](https://github.com/fmtlib/fmt){:target="_blank"}
*   **Official Documentation**: [https://fmt.dev](https://fmt.dev){:target="_blank"}
*   **StackOverflow Q&A**: [https://stackoverflow.com/questions/tagged/fmt](https://stackoverflow.com/questions/tagged/fmt){:target="_blank"}