Reputation: 267
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 a aligned manner.I am currently using the `t` character to do this but this will result in a misalignment if the data in one of the variable is too long.
How do I properly display data in a table form in C++?
Upvotes: 4
Views: 2746
Reputation: 5706
you can use setfill
and setw
to set the fill char and width of the columns. The problem is you are going to have to limit the columns for it to look right.
Upvotes: 1
Reputation: 97948
You can use std::setw
to set string width:
std::cout << std::setw (5) << "ASM" << std::endl;
So instead of using tabs, pad your string to a sufficiently large length.
Upvotes: 5