Есть ответ 👍

Виды электронных справочников и словарей. Нигде найти не могу

255
281
Посмотреть ответы 1

Ответы на вопрос:


Уменя есть какие-то наработки, они под линукс, но на винде должно работать все, кроме цветом, его выкинешь. #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

Популярно: Информатика