C++强大、高性能、易于使用的format库

 

fmtlib/fmt: A modern formatting library (github.com)

 

{fmt} is an open-source formatting library providing a fast and safe alternative to C stdio and C++ iostreams.

 

Documentation

Cheat Sheets

Q&A: ask questions on StackOverflow with the tag fmt.

Try {fmt} in Compiler Explorer.

Features

  • Simple format API with positional arguments for localization
  • Implementation of C++20 std::format
  • Format string syntax similar to Python's format
  • Fast IEEE 754 floating-point formatter with correct rounding, shortness and round-trip guarantees using the Dragonbox algorithm
  • Portable Unicode support
  • Safe printf implementation including the POSIX extension for positional arguments
  • Extensibility: support for user-defined types
  • High performance: faster than common standard library implementations of (s)printf, iostreams, to_string and to_chars, see Speed tests and Converting a hundred million integers to strings per second
  • Small code size both in terms of source code with the minimum configuration consisting of just three files, core.hformat.h and format-inl.h, and compiled code; see Compile time and code bloat
  • Reliability: the library has an extensive set of tests and is continuously fuzzed
  • Safety: the library is fully type-safe, errors in format strings can be reported at compile time, automatic memory management prevents buffer overflow errors
  • Ease of use: small self-contained code base, no external dependencies, permissive MIT license
  • Portability with consistent output across platforms and support for older compilers
  • Clean warning-free codebase even on high warning levels such as -Wall -Wextra -pedantic
  • Locale independence by default
  • Optional header-only configuration enabled with the FMT_HEADER_ONLY macro

See the documentation for more details.

 

 

posted @ 2023-07-25 14:03  sinferwu  阅读(233)  评论(0编辑  收藏  举报