Ответы на вопрос:
Уменя есть какие-то наработки, они под линукс, но на винде должно работать все, кроме цветом, его выкинешь. #include < cstdlib> #include < string> #include < iostream> #include "field.h"using namespace std; int main(int argc, char** argv, char** env){ srand(time(0)); vector< vector< string > > s; s.resize(2); s[0].push_back("vremena_goda"); s[1].push_back("zima"); s[1].push_back("vesna"); s[1].push_back("leto"); s[1].push_back("osen"); field a(s, , ); cout < < a < < std: : endl; return 0; } #ifndef field_h_included#define field_h_included #include < vector> #include < iterator> #include < algorithm> #include < string> #include < sstream> class field{public: enum consolecolor { clblack, clred, clgreen, clyellow, clblue, clpurple, cllightblue, clwhite }; private: size_t field_width, field_height; std: : vector< std: : vector< std: : string > > data; std: : vector< size_t > column_width; consolecolor color_border, color_font; std: : string get_format_color_string(std: : string s, consolecolor color) { std: : stringstream result; result < < "\x1b[1; " < < color + 30 < < "m" < < s < < "\x1b[0m"; return result.str(); } std: : string str_mul(std: : string s, size_t num) { std: : string result = ""; for(size_t i = 0; i < num; i++) result += s; return result; }public: field() {}; field(std: : vector< std: : vector< std: : string > > d, consolecolor color_border, consolecolor color_font) : data(d), color_border(color_border), color_font(color_font) { field_height = data.size(); field_width = 0; for(size_t i = 0; i < field_height; i++) field_width = std: : max(field_width, data[i].; for(size_t i = 0; i < field_height; i++) while(data[i].size() < field_width) data[i].push_back(""); column_width.assign(field_width, 0); for(size_t i = 0; i < field_height; i++) for(size_t j = 0; j < field_width; j++) column_width[j] = std: : max(column_width[j], data[i][j].; } void logs() { std: : cout < < "field_height: " < < field_height < < std: : endl; std: : cout < < "field_widht: " < < field_width < < std: : endl; } friend std: : ostream& operator < < (std: : ostream& output_stream, field & field) { /* std: : cout < < field.field_width < < " " < < field.field_height < < std: : endl; for(size_t i = 0; i < field.data.size(); i++) { for(size_t j = 0; j < field.data[i].size(); j++) std: : cout < < field.data[i][j] < < " "; std: : cout < < std: : endl; } */ output_stream < < field.get_format_color_string(" ┌", field.color_border); for(size_t i = 0; i < field.field_width - 1; i++) { output_stream < < field.get_format_color_string(field.str_mul("─", field.column_width[i] + 2), field.color_border); output_stream < < field.get_format_color_string("┬", field.color_border); } output_stream < < field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border); output_stream < < field.get_format_color_string("┐\n ", field.color_border); for(size_t i = 0; i < field.field_height; i++) { output_stream < < field.get_format_color_string("│", field.color_border); for(size_t j = 0; j < field.field_width; j++) { std: : stringstream ss; ss < < field.str_mul(" ", field.column_width[j] - field.data[i][j].size() + 1) < < (field.data[i][j] ! = "" ? field.data[i][j] : ""); output_stream < < field.get_format_color_string(ss. field.color_font); output_stream < < field.get_format_color_string(" │", field.color_border); } output_stream < < "\n "; if(i ! = field.field_height - 1) { output_stream < < field.get_format_color_string("├", field.color_border); for(size_t j = 0; j < field.field_width - 1; j++) { output_stream < < field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border); output_stream < < field.get_format_color_string("┼", field.color_border); } output_stream < < field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border); output_stream < < field.get_format_color_string("┤", field.color_border); } else { output_stream < < field.get_format_color_string("└", field.color_border); for(size_t j = 0; j < field.field_width - 1; j++) { output_stream < < field.get_format_color_string(field.str_mul("─", field.column_width[j] + 2), field.color_border); output_stream < < field.get_format_color_string("┴", field.color_border); } output_stream < < field.get_format_color_string(field.str_mul("─", field.column_width[field.field_width - 1] + 2), field.color_border); output_stream < < field.get_format_color_string("┘\n", field.color_border); } output_stream < < "\n "; } return output_stream; }}; #endif // field_h_included
Популярно: Информатика
-
happymenfeed19.10.2020 22:47
-
Vika294715.12.2020 00:37
-
07спиннер0702.01.2023 23:48
-
YaKrevedko125.03.2021 18:56
-
suxova198525103004.09.2021 16:21
-
sasharsm19.06.2021 03:46
-
ева51418.10.2020 12:15
-
солнвшко12.06.2021 04:48
-
Temka33333327.08.2021 11:12
-
круголс29.09.2022 16:44