[ACCEPTED]-Align cout format as table's columns-format
Accepted answer
setw.
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
cout << setw(21) << left << "Test" << 1 << endl;
cout << setw(21) << left << "Test2" << 2 << endl;
cout << setw(21) << left << "Iamlongverylongblah" << 2 << endl;
cout << setw(21) << left << "Etc" << 1 << endl;
return 0;
}
0
I advise using Boost Format. Use something like this:
cout << format("%|1$30| %2%") % var1 % var2;
0
You must find the length of the longest 6 string in the first column. Then you need 5 to output each string in the first column 4 in a field with the length being that of 3 that longest string. This necessarily means 2 you can't write anything until you've read 1 each and every string.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.