MCPcopy Create free account
hub / github.com/p-ranav/tabulate / main

Function main

samples/iterators.cpp:5–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3using Row_t = Table::Row_t;
4
5int main() {
6 Table table;
7
8 table.add_row(Row_t{"Company", "Contact", "Country"});
9 table.add_row(Row_t{"Alfreds Futterkiste", "Maria Anders", "Germany"});
10 table.add_row(Row_t{"Centro comercial Moctezuma", "Francisco Chang", "Mexico"});
11 table.add_row(Row_t{"Ernst Handel", "Roland Mendel", "Austria"});
12 table.add_row(Row_t{"Island Trading", "Helen Bennett", "UK"});
13 table.add_row(Row_t{"Laughing Bacchus Winecellars", "Yoshi Tannamuri", "Canada"});
14 table.add_row(Row_t{"Magazzini Alimentari Riuniti", "Giovanni Rovelli", "Italy"});
15
16 // Set width of cells in each column
17 table.column(0).format().width(40);
18 table.column(1).format().width(30);
19 table.column(2).format().width(30);
20
21 // Iterate over cells in the first row
22 for (auto &cell : table[0]) {
23 cell.format().font_style({FontStyle::underline}).font_align(FontAlign::center);
24 }
25
26 // Iterator over cells in the second column
27 for (auto &cell : table.column(0)) {
28 if (cell.get_text() != "Company") {
29 cell.format().font_align(FontAlign::right);
30 }
31 }
32
33 // Iterate over rows in the table
34 size_t index = 0;
35 for (auto &row : table) {
36 row.format().font_style({FontStyle::bold});
37
38 // Set blue background color for alternate rows
39 if (index > 0 && index % 2 == 0) {
40 for (auto &cell : row) {
41 cell.format().font_background_color(Color::blue);
42 }
43 }
44 index += 1;
45 }
46
47 std::cout << table << std::endl;
48}

Callers

nothing calls this directly

Calls 4

add_rowMethod · 0.45
widthMethod · 0.45
formatMethod · 0.45
columnMethod · 0.45

Tested by

no test coverage detected