Meugiwara
Meugiwara

Reputation: 749

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

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 ?

Upvotes: 3

Views: 569

Answers (1)

vitaut
vitaut

Reputation: 55595

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

Upvotes: 1

Related Questions