Pretty print a table in C++

print table format c++
how to print data in table format in c
c++ table
printf in c
c++ table library
multiplication table c++
setw in c++
format table output c++

I am looking for a library similar to prettytable but in C++

http://code.google.com/p/prettytable/

I know how to generate one myself using either printf or iostream. However, I would like to know if there is a library for this.

I am interested only in writing this ASCII table to the console.

Preferably something like:

std::vector<std::string> headers;
headers.push_back("My Awesome Header 1");
headers.push_back("My Awesome Header 2");
headers.push_back("My Awesome Header 3");


PrettyTablePrinter ptp;
ptp.SetHeaders(headers);
// Set some other options here
ptp.AddRow(data[0]);
ptp.AddRow(data[1]);
ptp.AddRow(data[2]);

ptp.Print(&std::cout);

Since I have not found a good C++ solution, I have written one for you all

https://github.com/dattanchu/bprinter/wiki

Pretty Print Tables, The data will be output in either CSV format or a pretty printed table The format parameter for table_row() takes a C style format string. With gcc, pass the option -std=c++11. Description. cxx-prettyprint is a header-only library for C++ which provides printing via the <<-operator for any container class. Before we go into the details, let us quickly think about what we need to do: An empty container should print as []. A container with a single element should print as [3].

I wasn't satisfied with any of the ones I found online so I wrote my own: https://github.com/friedmud/variadic_table

It uses variadic templates to allow each column to hold a different type. It also only requires C++11.

VariadicTable<std::string, double, int, std::string> vt({"Name", "Weight", "Age", "Brother"});

vt.addRow({"Cody", 180.2, 40, "John"});
vt.addRow({"David", 175.3, 38, "Andrew"});
vt.addRow({"Robert", 140.3, 27, "Fande"});

vt.print();

This will output:

--------------------------------------
| Name |  Weight  |    Age   |Brother|
--------------------------------------
|Cody  |     180.2|        40|John   |
|David |     175.3|        38|Andrew |
|Robert|     140.3|        27|Fande  |
--------------------------------------

This is actively being used in a large software project - so it will be maintained and developed over time. Feel free to submit issues / PRs

Printing a table of strings and data?, Printing a table of strings and data? I would like to output my data in columns with headers. I looked at some printf escape sequences, but haven't  It sounds like you need to define a default width for your printing format. Can you show us how you are printing. std::cout or printf() – linuxuser27 Oct 5 '10 at 19:47

While not exactly what you're looking for, Boost.Spirit contains a library (named Karma) usable to generate this kind of output fairly easily. The docs are here.

Formatted Output and the printf function, In C, a "string" is a sequence of one or more characters that the programmer intends to use as a unit Printing things in tables makes output more readable. I am new in C, still trying to figure out some of the formatting stuff. I was wondering how would print an array giving it a specific number of columns and align the array elements to the right or left. So if I use an integer array (one dimensional), how can I print the array in a table format with rows and columns?

12.8 Pretty Printing, v : any/c. Returns #t if v is a style table for use with pretty-print-current-style-table, #f otherwise. A way to pretty print a C# object. Ask Question Asked 8 years, 10 months ago. Browse other questions tagged c# pretty-print or ask your own question.

It's pretty simple to write an html to create tables in C++, you don't need a library for that. On the other hand if you want table output on console, it can be done, but it's not that easy, especially if you need to do vertical alignment, breaking strings, etc.

[PDF] Secrets of “printf”, printf is the C language function to do format- This was very useful in printing tables because small To make things line up nice and pretty, it is common. Most pure lua print table functions I've seen have a problem with deep recursion and tend to cause a stack overflow when going too deep. This print table function that I've written does not have this problem. It should also be capable of handling really large tables due to the way it handles concatenation.

How can I format a table to look nice?, Mathematica doesn't do the slickest table formatting in the world, but you can do quite To obtain the list from your code, do away with the Print statements, and table = {{"Segment", Column[{"Skin temperature [\[Degree]C]", "@ cold stable  PrettyTable tutorial shows how to use Python PrettyTable module to generate ASCII tables in Python. In this tutorial we use the PTable module, which is a fork of the original PrettyTable library. PrettyTable is a Python library for generating simple ASCII tables.

Tableprint, Tableprint is a library for printing out numerical data in Ascii formatted tables. Tableprint offers two functions that print a table directly, tableprint.table and  Enter an integer: 9 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81 9 * 10 = 90. Here's a little modification of the above program to generate the multiplication table up to a range (where range is also a positive integer entered by the user).

cxx-prettyprint: A C++ Container Pretty-Printer, Download: prettyprint.hpp (C++11), prettyprint98.hpp (C++98/03), or the zip ball or on hash tables (such as the unordered_* containers in the standard library). Prettyprint (or pretty-print) is the application of any of various stylistic formatting conventions to text files, such as source code, markup, and similar kinds of content. These formatting conventions can adjust positioning and spacing ( indent style ), add color and contrast ( syntax highlighting ), adjust size, and make similar

Comments
  • Related: stackoverflow.com/questions/2950639/printing-2d-table-headers/…