Displaying tables in a C ++ console window

cout<<" Name\t" <<"Cat\t" <<"Barcode\t" <<"Price\t" <<"Manufa\t" <<"Stock\t" <<"Sold\t" <<"ExDate\t " <<"Disc"<<endl; for (unsigned int i=0; i < _storage.size(); i++) { cout <<i <<":"; _storage[i]->showData(); cout<<endl; } 

I am trying to display data in order. I am currently using the `t` character for this, but this will lead to misalignment if the data in one of the variables is too long.

How to display data in table form in C ++?

+4
source share
2 answers

you can use setfill and setw to set the char fill and column width. The problem is that you have to constrain the columns to make them look right.

+1
source

You can use std::setw to set the line width:

std::cout << std::setw (5) << "ASM" << std::endl;

Therefore, instead of using tabs, put your string on a sufficiently large length.

+5
source

Source: https://habr.com/ru/post/1400680/


All Articles