Pretty print a table in C++

前端 未结 8 1028
眼角桃花
眼角桃花 2020-12-28 09:25

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 i

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 10:03

    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 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

提交回复
热议问题