Demonstrates the fix for https://github.com/p-ranav/tabulate/issues/62: print the header immediately, then stream each row to stdout as soon as it's computed/added, instead of waiting to print the whole table at once. This only works with fixed column widths: a later, wider row can't retroactively widen a column whose border has already been printed.
| 9 | // This only works with fixed column widths: a later, wider row can't |
| 10 | // retroactively widen a column whose border has already been printed. |
| 11 | int main() { |
| 12 | Table table; |
| 13 | table.add_row(Row_t{"Step", "Result"}); |
| 14 | table.column(0).format().width(10); |
| 15 | table.column(1).format().width(12); |
| 16 | table.print_row(0); // print the header as soon as it's added |
| 17 | |
| 18 | for (int step = 1; step <= 3; ++step) { |
| 19 | // ... pretend some computation happens here ... |
| 20 | table.add_row(Row_t{"Step " + std::to_string(step), step % 2 == 0 ? "OK" : "FAILED"}); |
| 21 | table.print_row(table.size() - 1); // stream the new row immediately |
| 22 | } |
| 23 | |
| 24 | table.print_bottom_border(); |
| 25 | } |