About
This C++ template formats and prints tabular data.
It calculates column widths after all fields are known.
The header-only template requires a C++03 compiler and the standard
library.
Copy PrettyTable.h and AlphaNum.h into a project to use it.
Column sorting uses Dirk Jagdmann’s implementation of the
alphanum algorithm for human-friendly ordering.
The following snippet shows typical usage:
CPrettyTable<int, const char*, double> tbl("num", "name", "score");
for (int i = 0; i < 5; ++i) {
tbl.Add(i + 1, "FooBar", 2.5 * (i + 1));
}
tbl.SetCaption("FooBar");
tbl.Dump(std::cerr);
The code prints the following output to the standard error stream:
What the numbers point at
-
1
SetCaptionembeds its text into the first delimiter line instead of printing a separate title row. -
2
Column titles come straight from the constructor arguments — there's no separate header-setting call.
-
3
Numeric types report
is_specialized=true, soCPrettyTableright-aligns them automatically. Strings stay left-aligned. -
4
Column widths are fixed only after every row is known, so a five-character caption or a six-character name both fit without truncation.
Build
Test
redo test builds the debug application and compares its output with the
recorded golden file.
redo lint applies the following linters to the source files:
actionlint,
checkmake,
reuse,
shellcheck,
shfmt,
typos,
yamllint,
zizmor.
License
ptable is copyrighted by David Rabkin and available under the
Zero-Clause BSD license.