For example, let us say that I am outputting
std::vector<std::vector<double>> A;
by the following:
for (int i = 0 ; i < rows ; i ++){
for (int j = 0 ; j < cols ; j ++){
cout << A[i][j] << " ";
}
std::cout << std::endl;
}
for a 3 x 3 matrix, the output would look something like:
1 3.7 2.89
3 4.85 12.34
4 5 6
as a contrived example.
I'd like to get it to look like:
1 3.7 2.89
3 4.85 12.34
4 5 6
Aligning the 1's position of the data so as to make it a bit more nicely formatted.
Does anyone have any suggestion for how to go about it? Something hidden in the iomanip
library maybe?
I'm currently working on the following implementation:
- transfer each row to string data
- check sizes of strings
- pick largest row (lr)
- for every prior column element, find the element in that column with max length, compare it to length of lr's column element, and add that many spaces between that output of lr and the prior element
- do some complex indexing :(