Can C++ draw a table for matrix? or I must draw a line like this?
__________________________
__________________________
_________________________
_________________________

Dani AI

Generated

Short answer: standard C++ does not include a single built‑in "draw table with borders" command like Maple. Which approach you choose depends on the output medium (console, GUI, file). was right to ask about the medium; and pointed toward the right technique — generate the layout with code (typically nested loops) and format each cell. Below is a minimal, practical console example you can adapt.

#include <iostream>
#include <iomanip>
#include <vector>

void printSeparator(int cols, int w){
    std::cout << '+';
    for(int c=0;c<cols;++c){ std::cout << std::string(w,'-') << '+'; }
    std::cout << '\n';
}

void printTable(const std::vector<std::vector<int>>& M, int w=4){
    if(M.empty()) return;
    int rows = M.size(), cols = M[0].size();
    printSeparator(cols,w);
    for(int r=0;r<rows;++r){
        std::cout << '|';
        for(int c=0;c<cols;++c){
            std::cout << std::setw(w) << M[r][c] << '|';
        }
        std::cout << '\n';
        printSeparator(cols,w);
    }
}

Notes and practical tips for large matrices (e.g. 140x140 or 400x400): a text terminal will not display very wide tables nicely and printing huge tables is slow and hard to read. Instead:

  • Export as CSV/TSV or an HTML table and open in a spreadsheet/browser for paging and zoom.
  • Use a GUI table widget (Qt QTableView, wxGrid) or an interactive terminal UI (ncurses) if you need browsing/selection.
  • Render to an image (SDL/SFML or a simple PNG library) when you need a printable layout like a timetable.
  • For performance, stream output to a file (avoid heavy per-char flushing) and choose a sensible cell width or show a submatrix.

If the goal is a readable "school timetable" view, print row/column headers and fixed cell widths rather than drawing every tiny line for very large matrices.

Recommended Answers

All 11 Replies

Or a nested for loop of '_'

I dont understand a nested for loop of '_'

Perhaps we should ask: what do you mean by a "table for matrix"? And on what medium do you want to draw it (console, gui window, printer paper)?

let me explain, I want to a 2 dimensional array which consist 140*140 and i do it in matrix form. So, if I have do a array, did C++ have a function to draw a line for the array?
Its look like school timetable.
_________________________
|_i,j_|_1_|_2_|__3_|__4_|_5__|
|_1__|___|___|____|____|____|
|_2__|___|___|____|____|____|
|_3__|___|___|____|____|____|

I want above line...or I must draw it bymyself?

1

You must draw it "bymyself."

What medium do you want to draw it on...

if I have a 400*400? so I must draw it myself.?
Huhuhuhu
So, C++ doest have a function to draw like a maple 11.

if I have a 400*400? so I must draw it myself.?
Huhuhuhu
So, C++ doest have a function to draw like a maple 11.

>What medium do you want to draw it on...

Considering his lack of information, I think it's safe to assume the medium is a terminal.

I repeat, you must draw it yourself.

or, you can design an algorithm to draw it for you... consisting in a series of nested loops...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.