Hey guys, I'm trying to figure out how to format my output with a max width so everything is lined up nicely. I am printing various strings x amount of times depending on the value at i in a vector.
For example, if M=3, D=5, R=13, then I want it to display like
---------------------------------
| M | M | M | D | D | D | D | D |
---------------------------------
| R | R | R | R | R | R | R | R |
---------------------------------
| R | R | R | R | R |
`---------------------
where the max width of '-' is 35 or max string/chars is 8 per row.
My code however prints like this
---------------------------------
| M | M | M | D | D | D | D | D | R | R | R | R | R | R | R | R | R | R | R | R | R |
Where it just continues straight instead of wrapping around like a grid.
I have tried placing more setw()'s for each string but I'm not getting it right. I'm not sure to approach this mathematically or continue using iomanip functions.
Here's my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
vector<int> totalM = {3, 6, 2};
vector<int> totalD = {5, 7, 9};
vector<int> totalR = {13, 22, 17};
int numSetsTotal = 3; // amount per vector
for (i=0; i < numSetsTotal; i++) {
cout << setfill('-') << setw(35) << endl;
cout << "\n|";
for (j = 0; i < totalM.at(i); j++) {
cout << setfill(' ') << " M |";
// FIXME: I want the string/char to output sizeatvect times with a max output width of 35
}
for (j = 0; j < totalD.at(i); j++) {
cout << " D |";
}
for(j = 0; j < totalR.at(i); j++) {
cout << " R |";
}
}
|