Your First Table
This guide will walk you through creating a simple, formatted CLI table using Tabular. We’ll build a table displaying countries and their capitals.Include the headers
Start by including the necessary Tabular headers in your C++ file:
table.h: Provides theTableclass for creating tablesrender.h: Provides therender()function for cross-platform output
Create a Table object
In your The
main() function, create a Table instance:Table class is the core component for building your CLI table.Add rows to the table
Use the
addRow() method to populate your table with data:- Each
addRow()call takes a vector of strings - The method returns a reference to the table, allowing method chaining
- Rows can have different numbers of columns (flexible tables)
Complete Example
Here’s the complete code from the example:Compile and Run
Compile your program with C++11 support:Expected Output
Your program will output a nicely formatted table:The default table width is 50 characters. You can customize this and many other aspects of your table.
Alternative Output Method
For simple ASCII tables, you can also usestd::cout directly:
render() function for proper cross-platform display.
Next Steps
Now that you’ve created your first table, explore more features:Width System
Learn how to configure table width, alignment, and padding
Styling
Add colors, text attributes, and visual effects to your tables
Borders
Customize table borders with pre-defined templates or create your own
Examples
Explore more examples and advanced features
Tips
- Method Chaining:
addRow()returns a reference to the table, allowing you to chain multiple calls - Flexible Columns: Rows can have different numbers of columns - Tabular handles this automatically
- Default Width: Tables default to 50 characters wide, but this is easily customizable with
table.config().width() - Unicode Support: Always use
render()for tables with Unicode characters to ensure proper display