Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

{fmt} Replace only one positional argument in string several positional arguments

Tags:

c++

fmt

I would like to know if {fmt} library allows to amend only one positional argument in string containing several positional arguments ?

Here is my test which doesn't work and {fmt} documentation shows no solution

std::string text = "{name} is {nb} years old and lives in {city}";
try
{
    text = fmt::format(text, fmt::arg("name", "John"));
}
catch (const fmt::format_error::exception &e)
{
    std::cout << e.what() << std::endl;
}

I would like to get John is {nb} years old and lives in {city}, is it possible ?

like image 459
Meugiwara Avatar asked Mar 07 '26 14:03

Meugiwara


1 Answers

No. Referring to a non-existent argument, positional or not, is an error.

like image 115
vitaut Avatar answered Mar 10 '26 04:03

vitaut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!