Fmt: Passing the field width as an argument

Created on 29 Jun 2016  路  3Comments  路  Source: fmtlib/fmt

How do I pass the field width as an argument? All the examples that use a field width have it hardcoded in the string, e.g., format("{:<30}", "left aligned");

Most helpful comment

The width and precision fields allow an integer or arg_id to be specified:
http://fmtlib.net/latest/syntax.html#grammar-token-width
See:
https://github.com/fmtlib/fmt/issues/303#issuecomment-208329512

All 3 comments

The width and precision fields allow an integer or arg_id to be specified:
http://fmtlib.net/latest/syntax.html#grammar-token-width
See:
https://github.com/fmtlib/fmt/issues/303#issuecomment-208329512

And applying to your example, @gnzlbg, what @mwinterb wrote, we get:

format("{:<{}}", "left aligned", 30);

Thanks you two!

Was this page helpful?
0 / 5 - 0 ratings