C++ 格式化庫:cppformat
cppformat (C++ Format) 是一個既輕便、安全,又快捷的開源 C++ 格式化庫。它可以用來取代 IOStreams ,同時也是格式輸出中較為安全的替代品。
特性
- Two APIs: faster concatenation-based write API and slower (but still very fast) replacement-based format API with positional arguments for localization.
- Write API similar to the one used by IOStreams but stateless allowing faster implementation.
- Format API with format string syntax similar to the one used by str.format in Python.
- Safe printf implementation including the POSIX extension for positional arguments.
- Support for user-defined types.
- High speed: performance of the format API is close to that of glibc's printf and better than performance of IOStreams. See Speed tests and Fast integer to string conversion in C++.
- Small code size both in terms of source code (format consists of a single header file and a single source file) and compiled code. See Compile time and code bloat.
- Reliability: the library has an extensive set of unit tests.
- Safety: the library is fully type safe, errors in format strings are reported using exceptions, automatic memory management prevents buffer overflow errors.
- Ease of use: small self-contained code base, no external dependencies, permissive BSD license.
- Portability with consistent output across platforms and support for older compilers.
- Clean warning-free codebase even on high warning levels (-Wall -Wextra -pedantic).
- Support for wide strings.
- Optional header-only configuration enabled with theFMT_HEADER_ONLYmacro.
示例
This prints Hello, world! to stdout:
fmt::print("Hello, {}!", "world"); // uses Python-like format string syntax fmt::printf("Hello, %s!", "world"); // uses printf format string syntax
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!