I am trying to print a 2d matrix in c++. I have a 2D array of integers. The output looks like this:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60
0 0 0 0 0 0 0 0 0 0 60 60 60 60 60 60 60 60 60 60 100 100 100 100 100 100 100 100 100 100 160
My code simply does 2 loops and adds an space after each number (and a newline after every row). Is there an easy way to print nicely formatted matrix in cpp. Something that would be more readable like so:
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 60 60 60 60 60
0 0 0 0 0 0 60 60 100 100 160
Code:
for(int i = 0; i <= n ; i++){
for(int w = 0; w <= W ; w++){
std:cout<<some_array[i][w]<<" ";
}
std::cout << std::endl;
}