Evo C++ Library v0.5.1
Additional Formatting

Additional text formatting helpers, compatible with String, Stream, and StreamOut types.

Tables

FmtTable is used to setup table column information and FmtTableOut (or a helper that returns this) is used to format and write the table to a string or stream.

The easiest way to format a table is with fmt_table(), which caches the output internally in order to determine the best column alignment.

#include <evo/fmt.h>
#include <evo/io.h>
using namespace evo;
int main() {
Console& c = con();
const SubString NAMES[] = {
"Name",
"ID",
"Balance",
"Location",
""
};
FmtTable table(NAMES, 0);
fmt_table(c.out, table)
<< "John Smith" << 1001 << 9.50 << "Los Angeles" << NL
<< "Jane Doe" << 1002 << 19.75 << "New York" << NL
<< fFLUSH;
return 0;
}

Output:

Name ID Balance Location
John Smith 1001 9.5 Los Angeles
Jane Doe 1002 19.75 New York

To avoid caching overhead use fmt_table_nocache() to write table output directly. To keep columns aligned, FmtTableAttribs is useful for updating column widths first.

#include <evo/fmt.h>
#include <evo/io.h>
using namespace evo;
int main() {
Console& c = con();
const SubString NAMES[] = {
"Name",
"ID",
"Balance",
"Location",
""
};
FmtTable table(NAMES, 0);
FmtTableAttribs(table) << 10 << 5 << 11;
<< "John Smith" << 1001 << 9.50 << "Los Angeles" << NL
<< "Jane Doe" << 1002 << 19.75 << "New York" << NL;
return 0;
}

Output:

Name ID Balance Location
John Smith 1001 9.5 Los Angeles
Jane Doe 1002 19.75 New York