std:: vformat
|
ヘッダーで定義
<format>
|
||
|
std::
string
vformat
(
std::
string_view
fmt,
std::
format_args
args
)
;
|
(1) | (C++20以降) |
|
std::
wstring
vformat
(
std::
wstring_view
fmt,
std::
wformat_args
args
)
;
|
(2) | (C++20以降) |
|
std::
string
vformat
(
const
std::
locale
&
loc,
std:: string_view fmt, std:: format_args args ) ; |
(3) | (C++20以降) |
|
std::
wstring
vformat
(
const
std::
locale
&
loc,
std:: wstring_view fmt, std:: wformat_args args ) ; |
(4) | (C++20以降) |
args に保持されている引数を、書式文字列 fmt に従ってフォーマットし、結果を文字列として返します。存在する場合、 loc はロケール固有のフォーマットに使用されます。
目次 |
パラメータ
| fmt | - |
フォーマット文字列を表すオブジェクト。フォーマット文字列は以下から構成される:
各置換フィールドは以下の形式を持つ:
1)
フォーマット指定なしの置換フィールド
2)
フォーマット指定ありの置換フィールド
|
||||||||||||||||||||||||||||||||||||||||||||||
| args | - | フォーマットする引数 | ||||||||||||||||||||||||||||||||||||||||||||||
| loc | - | ロケール固有のフォーマットに使用される std::locale | ||||||||||||||||||||||||||||||||||||||||||||||
戻り値
フォーマットされた結果を保持する文字列オブジェクト。
例外
以下の場合にスローする: std::format_error - fmt が指定された引数に対して有効なフォーマット文字列でない場合、または std::bad_alloc - メモリ確保に失敗した場合。また、フォーマッタ操作やイテレータ操作で発生した例外を伝播する。
例
#include <format> #include <iostream> template<typename... Args> inline void println(const std::format_string<Args...> fmt, Args&&... args) { std::cout << std::vformat(fmt.get(), std::make_format_args(args...)) << '\n'; } int main() { println("{}{} {}{}", "Hello", ',', "C++", -1 + 2 * 3 * 4); }
出力:
Hello, C++23