tapflow
팀 전체가 사용할 수 있는 자체 호스팅 iOS·Android 시뮬레이터 스트리밍
현대적인 포맷팅 라이브러리
A modern formatting library
개발 도구C++ · PythonGitHub @fmtlib직접 설치운영자 미확인
써 보셨어요? 한 번만 눌러 주세요. 로그인은 필요 없어요.
개인 계정의 공개 저장소 소유자는 GitHub로 로그인해 운영자를 확인하고 소개를 직접 관리할 수 있습니다. 관리자 승인은 필요하지 않습니다.
로그인한 뒤 확인 파일을 만들어 이 저장소의 기본 브랜치에 30분 안에 커밋해 주세요. 다른 브랜치나 포크의 파일은 인정하지 않습니다. 파일을 올린 뒤 아래에서 확인하면 관리자 승인 없이 관리할 수 있습니다. 자격을 유지하려면 파일을 남겨 두세요.
로그인이 필요하면 로그인 화면으로 이동합니다. 로그인 후 이곳으로 돌아와 원하는 확인 버튼을 다시 눌러 주세요.
설치형 프로젝트는 배포 도메인 없이도 확인할 수 있습니다. 개인 저장소는 GitHub 로그인으로, 조직 저장소는 위의 저장소 확인 파일로 직접 확인해 주세요.
메이커가 쓴 소개는 위의 한 줄이 전부입니다. 더 자세한 내용은 저장소 README에서 읽을 수 있습니다. 저장소 README ↗
README 전체를 불러오는 중입니다.
README 전문 보기 ↗{fmt} is an open-source formatting library providing a fast and safe alternative to C stdio and C++ iostreams.
Q&A: ask questions on StackOverflow with the tag fmt.
Try {fmt} in Compiler Explorer.
(s)printf, iostreams, to_string and
to_chars, see Speed tests and Converting a
hundred million integers to strings per
secondcore.h, format.h
and format-inl.h, and compiled code; see Compile time and code
bloatSee the documentation for more details.
Print to stdout (run)
#include <fmt/core.h>
int main() {
fmt::print("Hello, world!\n");
}
Format a string (run)
std::string s = fmt::format("The answer is {}.", 42);
// s == "The answer is 42."
Format a string using positional arguments (run)
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 (run)
#include <fmt/chrono.h>
int main() {
auto now = std::chrono::system_clock::now();
fmt::print("Date and time: {}\n", now);
fmt::print("Time: {:%H:%M}\n", now);
}
Output:
Date and time: 2023-12-26 19:10:31.557195597
Time: 19:10
Print a container (run)
#include <vector>
#include <fmt/ranges.h>
int main() {
std::vector<int> v = {1, 2, 3};
fmt::print("{}\n", v);
}
Output:
[1, 2, 3]
Check a format string at compile time
std::string s = fmt::format("{:d}", "I am not a number");
This gives a compile-time error in C++20 because d is an invalid
format specifier for a string.
Write a file from a single thread
#include <fmt/os.h>
int main() {
auto out = fmt::output_file("guide.txt");
out.print("Don't {}", "Panic");
}
This can be up to 9 times faster than fprintf.
Print with colors and text styles
#include <fmt/color.h>
int main() {
fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold,
"Hello, {}!\n", "world");
fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
fmt::emphasis::underline, "Olá, {}!\n", "Mundo");
fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic,
"你好{}!\n", "世界");
}
Output on a modern terminal with Unicode support:
{fmt} can be tens of percent to 20–30 times faster than sprintf and
iostreams, especially for numeric formatting. It minimizes dynamic memory
allocations and can optionally compile format strings into efficient formatting code.
See format-benchmark and dtoa-benchmark for benchmarks and methodology.
Time per double (smaller is better):
ostringstream and sprintf are omitted because they are an order of
magnitude slower than the other methods.
The script bloat-test.py from format-benchmark measures the
compile-time and code-size overhead each formatting method adds to application
code. It generates 100 translation units and uses printf or its alternative
five times in each to simulate a medium-sized project. Library and module build
costs are excluded. Results on an Apple M5 Max running macOS 26.6.2 with
Apple Clang 21.0.0 (clang-2100.1.1.101), taking the best of three runs, are
shown in the following tables.
Optimized build (-O3)
| Method | Compile time, s | Binary size, KiB | Stripped size, KiB |
|---|---|---|---|
| printf | 1.6 | 54 | 50 |
| IOStreams | 25.5 | 98 | 84 |
| fmt 12.2 (headers) | 5.1 | 54 | 50 |
| fmt 12.2 (module) | 3.7 | 59 | 50 |
| Boost Format 1.92 | 49.1 | 517 | 317 |
Using modular {fmt} reduces optimized application-code compile time by 27% without changing the reported stripped binary size.
Non-optimized build
| Method | Compile time, s | Binary size, KiB | Stripped size, KiB |
|---|---|---|---|
| printf | 1.6 | 54 | 50 |
| IOStreams | 26.0 | 88 | 68 |
| fmt 12.2 (headers) | 4.9 | 87 | 84 |
| fmt 12.2 (module) | 3.2 | 77 | 68 |
| Boost Format 1.92 | 35.7 | 741 | 431 |
libc, libc++, libfmt, and libfmt-module were linked as shared libraries
to compare formatting function overhead only. Boost Format is header-only.
Notable users include:
-Wall -Wextra -pedanticFMT_HEADER_ONLY macro