Console Library 4.7.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
console::f_string Class Reference

格式化字符串类,支持使用 % 运算符进行占位符 {} 替换。 More...

#include <strpp.h>

Inheritance diagram for console::f_string:

Public Member Functions

template<class T>
f_string operator% (const T &t)
 用参数替换第一个 {} 占位符。

Detailed Description

格式化字符串类,支持使用 % 运算符进行占位符 {} 替换。

继承自 std::string,通过 operator% 将第一个 {} 替换为参数的字符串表示。 若字符串中不包含 {} 则抛出 bad_format 异常。

使用示例:

f_string fmt = "Hello, {}!"_f;
std::string result = fmt % "world"; // "Hello, world!"
格式化字符串类,支持使用 % 运算符进行占位符 {} 替换。
Definition strpp.h:302

Member Function Documentation

◆ operator%()

template<class T>
f_string console::f_string::operator% ( const T & t)
inline

用参数替换第一个 {} 占位符。

Template Parameters
T参数类型。
Parameters
t要替换的值。
Returns
f_string 替换后的新 f_string 对象。
Exceptions
bad_format若当前字符串中不包含 {}

The documentation for this class was generated from the following file: