I am looking for a quick and neat way to print in a nice table format with cells being aligned properly.
Is there a convenient way in c++ to create strings of substrings with certain length like python format
"{:10}".format("some_string")
In C++20 you can use std::format
which brings Python-like formatting to C++:
auto s = std::format("{:10}", "some_string");
Until it is widely available you can use the open-source {fmt} formatting library, std::format
is based on.
Disclaimer: I'm the author of {fmt} and C++20 std::format
.
Try this https://github.com/fmtlib/fmt
fmt::printf("Hello, %s!", "world"); // uses printf format string syntax
std::string s = fmt::format("{0}{1}{0}", "abra", "cad");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With