In a C++ code I have a matrix of double variables which I print out. However because all of them have different number of digits, the output format is destroyed. One solution is to do
cout.precision(5) but I want different columns have a different precision. Also, because there are negative values in some cases, the presence of the - sign also causes problems. How to get around this and produce a properly formatted output?
In a C++ code I have a matrix of double variables which I print
Share
Off the top of my head, you can use setw(int) to specify the width of the output.
like this:
gives this: