{"name":"{fmt}: A Modern, Fast, and Safe Formatting Library for C++","description":"{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","url":"https://osrepos.com/repo/fmtlib-fmt","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/fmtlib-fmt","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/fmtlib-fmt.md","json":"https://osrepos.com/repo/fmtlib-fmt.json","topics":["c-plus-plus","cpp","formatting","performance","cross-platform","unicode","library","utility"],"keywords":["c-plus-plus","cpp","formatting","performance","cross-platform","unicode","library","utility"],"stars":null,"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.","content":"## Introduction\n`{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.\n\n## Installation\nTo 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.\n\nFor 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:\n[https://fmt.dev/latest/get-started/#building-from-source](https://fmt.dev/latest/get-started/#building-from-source){:target=\"_blank\"}\n\n## Examples\n`{fmt}` provides a versatile and intuitive API for various formatting tasks. Here are a few examples demonstrating its capabilities:\n\n**Print to stdout**\nc++\n#include <fmt/base.h>\n\nint main() {\n  fmt::print(\"Hello, world!\\n\");\n}\n\n\n**Format a string**\nc++\nstd::string s = fmt::format(\"The answer is {}.\", 42);\n// s == \"The answer is 42.\"\n\n\n**Format a string using positional arguments**\nc++\nstd::string s = fmt::format(\"I'd rather be {1} than {0}.\", \"right\", \"happy\");\n// s == \"I'd rather be happy than right.\"\n\n\n**Print dates and times**\nc++\n#include <fmt/chrono.h>\n#include <chrono>\n\nint main() {\n  auto now = std::chrono::system_clock::now();\n  fmt::print(\"Date and time: {}\\n\", now);\n  fmt::print(\"Time: {:%H:%M}\\n\", now);\n}\n\n\n**Print a container**\nc++\n#include <vector>\n#include <fmt/ranges.h>\n\nint main() {\n  std::vector<int> v = {1, 2, 3};\n  fmt::print(\"{}\\n\", v);\n}\n\n\n## Why Use {fmt}?\n`{fmt}` addresses several shortcomings of existing C++ formatting solutions, offering compelling advantages:\n\n*   **Performance**: It is significantly faster than `printf`, C++ iostreams, `to_string`, and `to_chars` in many benchmarks, especially for floating-point and integer formatting.\n*   **Type-Safety**: Unlike `printf`, `{fmt}` is fully type-safe, preventing common errors like format string mismatches at compile time (with C++20).\n*   **Modern API**: It offers a clean, intuitive API similar to Python's `str.format`, supporting positional arguments crucial for internationalization.\n*   **C++20/C++23 Compatibility**: `{fmt}` provides an implementation of `std::format` and `std::print`, allowing for a smooth transition to future C++ standards.\n*   **Extensibility**: Easily extendable to support user-defined types.\n*   **Small Code Size**: Minimal configuration requires only three files, leading to small compiled code size and fast compile times, comparable to `printf`.\n*   **Portability**: Consistent output across various platforms and support for older compilers.\n*   **Reliability**: Extensively tested and continuously fuzzed for robustness.\n*   **Ease of Use**: Self-contained, no external dependencies, and distributed under the permissive MIT license.\n\nMany 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.\n\n## Links\n*   **GitHub Repository**: [https://github.com/fmtlib/fmt](https://github.com/fmtlib/fmt){:target=\"_blank\"}\n*   **Official Documentation**: [https://fmt.dev](https://fmt.dev){:target=\"_blank\"}\n*   **StackOverflow Q&A**: [https://stackoverflow.com/questions/tagged/fmt](https://stackoverflow.com/questions/tagged/fmt){:target=\"_blank\"}","metrics":{"detailViews":5,"githubClicks":4},"dates":{"published":null,"modified":"2025-11-18T20:01:30.000Z"}}