Format output in a table, C++

Can't you do something very similar to the C# example of:

String.Format("|{0,5}|{1,5}|{2,5}|{3,5}|", arg0, arg1, arg2, arg3);

Like:

printf("|%5s|%5s|%5s|%5s|", arg0, arg1, arg2, arg3);

Here's a reference I used to make this: http://www.cplusplus.com/reference/clibrary/cstdio/printf/


Here's a small sample of what iomanip has:

#include <iostream>
#include <iomanip>

int main(int argc, char** argv) {
    std::cout << std::setw(20) << std::right << "Hi there!" << std::endl;
    std::cout << std::setw(20) << std::right << "shorter" << std::endl;
    return 0;
}

There are other things you can do as well, like setting the precision of floating-point numbers, changing the character used as padding when using setw, outputting numbers in something other than base 10, and so forth.

http://cplusplus.com/reference/iostream/manipulators/


I couldn't find something I liked, so I made one. Find it at https://github.com/haarcuba/text-table

Here's an exmaple of its output:

+------+------+----+
|      |Sex   | Age|
+------+------+----+
|Moses |male  |4556|
+------+------+----+
|Jesus |male  |2016|
+------+------+----+
|Debora|female|3001|
+------+------+----+
|Bob   |male  |  25|
+------+------+----+