I have the following member function:
void Matrix::print(std::ostream &os) {
for (unsigned i = 0; i < m_height; ++i) {
os << "| ";
for (unsigned j = 0; j < m_width; ++j) {
os << this->matrix[i][j] << " ";
}
os << "|" << "\n";
}
os << "\n";
}
which takes in an ostream as an input and prints out a matrix of doubles in a two dimensional array format. The bars I have added at the end of each row works great to simulate the appearance of a two dimensional array if all of the entries have the same number of digits, e.g., all entries are integers between 10 and 99 inclusive. However, the output is misaligned if the entries each have a different number of digits.
I was wondering if there was a quick fix for this, possibly to control the precision of each entry to a fixed length so that the output is aligned properly, or some other option.