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     |
+---+------------+----------+-----------+
相关推荐
青峰讲运维26 分钟前
OpenStack Heat 编排:用模板一键交付云业务,告别手动点页面
开发语言·php·openstack
MyFreeIT1 小时前
Python Windows Manual
开发语言·python
kiracrimson1 小时前
STL:List的使用和模拟实现
开发语言·c++·list
二十七日秋1 小时前
算法刷题笔记「Day 1|四道 OJ 入门题里的深坑」
c语言·汇编·数据结构·c++·笔记·python·算法
流年如夢1 小时前
继承与多态_继承篇
c++·继承·面向对象·c++进阶
北冥you鱼2 小时前
Go 语言 GORM 使用 Preload:从关联查询到嵌套预加载的完整实践
开发语言·jvm·golang
沫璃染墨2 小时前
从零入门计算机网络系列(十):HTTP协议进阶——从资源路径解析到状态码与请求头详解
linux·运维·服务器·网络·c++·http
dingzd952 小时前
TikTok账号登录态失效的Cookie字段排查路径
开发语言·php·跨境电商·营销策略
abc light2 小时前
ARM 裸机开发(1)——ARM 体系结构
c语言·arm开发
曹牧2 小时前
C#:The operation has timed out
开发语言·c#