Print a matrix to the console

Surprisingly, few people know and use the iomanip standard C++ library, that is why I put this snippet here. It is very simple, so I encourage you to take some minutes to discover its possibilities.

  cout << setprecision( 3 ) << right << fixed;
  for ( int row = 0; row < 3; ++ row )
  {
    for ( int col = 0; col < 3; ++ col )
    {
      cout << setw( 5 ) << (double)cvmGet( C, row, col ) << " ";
    }
    cout << endl;
  }

The output should look like this:

2.000 2.600 1.900
2.360 1.040 2.970
1.120 1.300 1.120

Snippets_for_debugging (last edited 2008-05-28 14:02:28 by localhost)

SourceForge.net Logo