当前位置: 首页 > news >正文

终端 数据表格

//
// Created by HongDaYu on 17 十月 2024.
//#ifndef HDYSDK_UTIL_H
#define HDYSDK_UTIL_H#include <cstdint>
#include <string>
#include <list>
#include <iomanip>
#include <memory>class dataGrid {
private:std::list<const char*> _table;int32_t col = 0;size_t width = 15;char split_char = '-';
public:explicit dataGrid(size_t w,int32_t col,char s='-'):width(w),split_char(s),col(col){}dataGrid &operator<<(const char*);const std::list<const char *> &getList(){return _table;}std::shared_ptr<char> table();
};#endif//HDYSDK_UTIL_H#include "util.h"
#include <list>
#include <iostream>
#include <cstring>
#include <strstream>dataGrid &dataGrid::operator<<(const char *row) {this->_table.push_back(row);return *this;
}std::shared_ptr<char> dataGrid::table() {size_t len = 0;size_t counts = 1;int32_t index = 0;for(auto it : _table){len+=strlen(it);counts++;}std::shared_ptr<char> grid(new char[len+width*counts*2]);std::ostrstream buffer(grid.get(),static_cast<int>(len+width*counts*2));for(auto it : _table){buffer << std::setw(static_cast<int>(width)) << std::left << it;if(((index+1)%col) == 0){if((index+1) == col)buffer << std::endl << std::setfill(split_char) << std::setw(static_cast<int>(width) * col) << "" << std::setfill(' ') << std::endl;elsebuffer << std::endl;}index++;}return grid;
}int main() {dataGrid buffer(15,2);buffer << "hello" << "world" << "very" << "good";std::cout << buffer.table();return 0;
}

在这里插入图片描述

一般只有开发人员在debug的时候,在调用一个库有点累赘


http://www.mrgr.cn/news/52607.html

相关文章:

  • 基于SSM的个性化商铺系统【附源码】
  • MAC 电脑Office power point编辑的时候,显示“某些字体无法随演示文稿一起保存,仍然要保存演示文稿吗?”
  • 【哈工大_操作系统理论】L2223 多级页表与快表段页结合的实际内存管理
  • React1-基础概念
  • 【c++篇】:初识c++--编程新手的快速入门之道(二)
  • 【C++】—— list迭代器
  • 看《米小圈日记魔法》突破写作困境一点也不难!
  • 【文心智能体 | AI大师工坊】如何使用智能体插件,完成一款购物类智能体的开发,来体验一下我的智能体『科技君Tom』
  • Vue 3 和 Vue 2区别
  • 学习 Flutter 的最佳路线图
  • Matlab中HybridFcn参数的用法
  • mysql--数据表的操作
  • memset的用法
  • [论文阅读]Stealing Machine Learning Models via Prediction APIs
  • Java集合常见知识总结(上)
  • Luogu P1528 切蛋糕 || SCOI2005 栅栏
  • es索引库操作和使用RestHignLevelClient客户端操作es
  • C++笔记之静态多态和动态多态
  • HarmonyOS NEXT 应用开发实战(六、组件导航Navigation使用详解)
  • laravel清除不同缓存