Skip to content

Commit 193cca8

Browse files
committed
增加 fmt
1 parent 1577625 commit 193cca8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

libs/cpp.wiki

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,28 @@ cout << format("%s %d") % "price" % 1234;
304304
// price 1234
305305
</source>
306306

307+
<h4>fmt</h4>
308+
309+
Home:[https://github.com/fmtlib/fmt]
310+
311+
这是一个轻量级、类型安全、高性能的字符串格式化库。它也可以用来替代 C++ 标准库中的 IOStreams。
312+
313+
代码示例
314+
<source lang="cpp">
315+
&#35;include <string>
316+
&#35;include <fmt/format.h>
317+
318+
// 使用 Python 的格式化语法
319+
fmt::print("Hello, {}!", "world");
320+
// 使用 printf 的格式化语法
321+
fmt::printf("Hello, %s!", "world");
322+
// 使用序号参数,
323+
std::string s = fmt::format("{0} {1} {0}", "Hello", "world");
324+
// 使用命名参数
325+
fmt::print("Hello, {name}! The answer is {number}. Goodbye, {name}.",
326+
fmt::arg("name", "World"), fmt::arg("number", 42));
327+
</source>
328+
307329
=== 2.3.3 正则表达式 ===
308330

309331
<h4>PCRE(Perl Compatible Regular Expressions)</h4>

0 commit comments

Comments
 (0)