std:: vformat
|
Défini dans l'en-tête
<format>
|
||
|
std::
string
vformat
(
std::
string_view
fmt,
std::
format_args
args
)
;
|
(1) | (depuis C++20) |
|
std::
wstring
vformat
(
std::
wstring_view
fmt,
std::
wformat_args
args
)
;
|
(2) | (depuis C++20) |
|
std::
string
vformat
(
const
std::
locale
&
loc,
std:: string_view fmt, std:: format_args args ) ; |
(3) | (depuis C++20) |
|
std::
wstring
vformat
(
const
std::
locale
&
loc,
std:: wstring_view fmt, std:: wformat_args args ) ; |
(4) | (depuis C++20) |
Formate les arguments contenus dans args selon la chaîne de format fmt , et retourne le résultat sous forme de chaîne. S'il est présent, loc est utilisé pour le formatage spécifique aux paramètres régionaux.
Table des matières |
Paramètres
| fmt | - |
un objet qui représente la chaîne de format. La chaîne de format est constituée de
Chaque champ de remplacement a le format suivant :
1)
champ de remplacement sans spécification de format
2)
champ de remplacement avec une spécification de format
|
||||||||||||||||||||||||||||||||||||||||||||||
| args | - | arguments à formater | ||||||||||||||||||||||||||||||||||||||||||||||
| loc | - | std::locale utilisé pour le formatage spécifique à la locale | ||||||||||||||||||||||||||||||||||||||||||||||
Valeur de retour
Un objet chaîne contenant le résultat formaté.
Exceptions
Lance std::format_error si fmt n'est pas une chaîne de format valide pour les arguments fournis, ou std::bad_alloc en cas d'échec d'allocation. Propage également toute exception levée par les opérations de formateur ou d'itérateur.
Exemple
#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); }
Sortie :
Hello, C++23