Search code examples
c++c++20stdformat

Inserting Characters in Placeholder in `std::format`


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)

Solution

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

    No.