c++fmt

How to align multiple fields together in fmt?


Is it possible to align multiple fields together?

E.g.,

std::format("{:{}:<12} text", file, line)

to align as

main.cpp:1   text

and not as

main.cpp:   1 text

Solution

  • Is it possible to align multiple fields together?

    No. But you can combine the fields first, and align the result later.

    std::format("{:<12} text\n", std::format("{}:{}", file, line));
    

    This produces

    main.cpp:1   text