Inserting Characters in Placeholder in `std::format`

130 views Asked by At

In the C++20 <format> library, is it possible to insert characters in a placeholder, so that those characters behave like a part of the passed parameter?

For example, I have the following statement:

std::format("Test '{:<{}}'", 123, 5)

which produces Test '123 '.

What I need it to produce is Test '123; ' (note the semicolon after 123 is left-justified together with 123).

In other words, is there a shorter alternative to this?

std::format("Test '{:<{}}'\n", std::format("{};", 123), 5)
1

There are 1 answers

0
KamilCuk On BEST ANSWER

In other words, is there a shorter alternative to this?

No.