fmt
What is fmt? A C++ formatting library, not a logging service
Understand fmt through its actual C++ APIs: typed formatting, output destinations, header organization and the difference between compile-time checks and compiled format strings.
What you will learn
- Start with the unit it actually provides
- Read the right header for the question
- Separate three kinds of convenience
Before you start
- Basic C++ values, references, strings and build targets
- Ability to distinguish a documented expectation from a measured result
Trace concrete fmt behavior and choose an integration with explicit output, lifetime and verification boundaries.
Key takeaways
- fmt is a C++ dependency with several output APIs, not an application service.
- Header roles and version claims are tied to the inspected commit.
- Compile-time checking, runtime parsing and compiled formatting are different mechanisms.
Start with the unit it actually provides
fmt turns typed C++ values and a format string into text. fmt::format returns a std::string, fmt::print writes to an output stream, and format_to variants write through iterators or bounded destinations. This makes it useful inside command-line programs, application diagnostics and report generators. It is a library that your application builds or links, not a hosted service with a database, model provider or deployment dashboard.
The review is pinned to commit 44f2c7a, checked on September 8, 2026. Its FMT_VERSION macro is 120201, corresponding to 12.2.1; that identifies the inspected source, not proof that a package manager ships this exact commit. The repository carries the MIT license. Retain the source revision and applicable notices when evaluating a dependency update.
Read the right header for the question
At this revision, fmt/core.h is the canonical minimal core API and fmt/base.h merely includes it as a compatibility header. fmt/format.h adds the string-returning format API and broader formatting support. Optional headers expose ranges, chronology, colors, operating-system helpers and dynamic argument storage. Include the API you actually use rather than treating every header as an independently deployed component.
This header arrangement changed in the inspected September 8 commit. Tutorials from another fmt revision may name a different core header. A reliable explanation links a fixed source path and shows its role; it should not silently combine old package instructions with the current main branch. The examples in this series use format.h where a returned std::string is needed.
Separate three kinds of convenience
A literal accepted by fmt::format_string can be checked during compilation on a compiler supporting the required C++20 consteval behavior. A string wrapped by fmt::runtime is checked at runtime instead. FMT_COMPILE is another mechanism: with suitable compiler support it turns a fixed format string into specialized formatting code. These are related features, not three names for the same guarantee.
Type checking does not make every surrounding operation safe. A string view still needs a live backing object, a raw output pointer still needs sufficient storage, and text going into HTML or a log protocol needs context-appropriate handling. Start with one concrete output and its ownership requirements, then decide whether fmt improves that part of the application.
Implementation steps
- 1
Choose whether the caller needs a string, stream output or a bounded destination.
- 2
Record the dependency commit and compiler configuration.
- 3
Include the relevant header and test one expected output.
- 4
Review ownership and output-context requirements separately.
Copy-ready example
#include <fmt/format.h>
#include <cassert>
int main() {
const auto message = fmt::format("id={:04}", 7);
assert(message == "id=0007");
}Frequently asked questions
Does fmt require a server or API key?
No. The reviewed formatting path is a C++ library integration, not a remote model or hosted formatting service.
Does version 12.2.1 identify an exact package build?
No. That is the macro value in the pinned source; package revision, build flags and distribution availability must be checked separately.
Sources
- README.mdSource checked 2026-09-08
- LICENSESource checked 2026-09-08
- CMakeLists.txtSource checked 2026-09-08
- doc/api.mdSource checked 2026-09-08
- include/fmt/core.hSource checked 2026-09-08
- include/fmt/base.hSource checked 2026-09-08
- include/fmt/format.hSource checked 2026-09-08
- include/fmt/compile.hSource checked 2026-09-08