C/C++:libfort用于在终端输出表格

libfort

用于在终端输出表格,提供了表格布局和样式设置的功能

https://github.com/seleznevae/libfort

示例: C示例

cpp 复制代码
#include <stdio.h>

#include "fort.h"

int main(void)
{
    ft_table_t *table = ft_create_table();

    /* Setup header */
    ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
    ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");

    ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
    ft_write_ln(table, "2", "Hamilton", "1:26.373", "221.027");
    ft_write_ln(table, "3", "Verstappen", "1:26.469", "220.782");

    printf("%s\n", ft_to_string(table));
    ft_destroy_table(table);

    return 0;
}

输出结果

shell 复制代码
$ gcc 1-simple_table.c ../lib/fort.c -I../lib  && ./a.out 

+---+------------+----------+-----------+
| N | Driver     | Time     | Avg Speed |
+---+------------+----------+-----------+
| 1 | Ricciardo  | 1:25.945 | 222.128   |
| 2 | Hamilton   | 1:26.373 | 221.027   |
| 3 | Verstappen | 1:26.469 | 220.782   |
+---+------------+----------+-----------+

示例: C++示例

cpp 复制代码
#include <iostream>

#include "fort.hpp"


int main()
{
    fort::char_table table;
    table << fort::header
        << "N" << "Driver" << "Time" << "Avg Speed" << fort::endr
        << "1" << "Ricciardo" << "1:25.945" << "47.362" << fort::endr
        << "2" << "Hamilton" << "1:26.373" << "35.02" << fort::endr
        << "3" << "Verstappen" << "1:26.469" << "29.78" << fort::endr;

    std::cout << table.to_string() << std::endl;
}

输出结果

shell 复制代码
g++ 1-simple_table.cpp ../lib/fort.c -I../lib  -std=c++11 && ./a.out

+---+------------+----------+-----------+
| N | Driver     | Time     | Avg Speed |
+---+------------+----------+-----------+
| 1 | Ricciardo  | 1:25.945 | 47.362    |
| 2 | Hamilton   | 1:26.373 | 35.02     |
| 3 | Verstappen | 1:26.469 | 29.78     |
+---+------------+----------+-----------+
相关推荐
RAY_01042 小时前
Python—数据可视化pyecharts
开发语言·python
徐同保2 小时前
n8n+GPT-4o一次解析多张图片
开发语言·前端·javascript
春日见2 小时前
如何跑通,吃透一个开源项目?
linux·运维·开发语言·数码相机·matlab
技术净胜2 小时前
MATLAB数据清洗流程包含:缺失值处理/异常值检测/重复值删除
开发语言·matlab
SmoothSailingT2 小时前
C#——textBox控件(1)
开发语言·c#
Dream it possible!2 小时前
LeetCode 面试经典 150_回溯_全排列(100_46_C++_中等)
c++·leetcode·面试·回溯
悦悦子a啊2 小时前
使用 Java 集合类中的 LinkedList 模拟栈以此判断字符串是否是回文
java·开发语言
Lucky小小吴2 小时前
java代码审计入门篇——Hello-Java-Sec(完结)
java·开发语言
csbysj20202 小时前
XML 技术
开发语言