How to make glog output not fill 0 before number?

143 Views Asked by At

When I use glog to print an Eigen matrix in console, I found the output format has difference when using std::cout against using LOG(INFO). Here is the source code, in which 'sophus_R' is a 3x3 matrix.

LOG(INFO) << "using glog, sophus_R is:\n" << sophus_R.matrix();
std::cout << "using std::cout, sophus_R is:\n" << sophus_R.matrix() << std::endl;

And here is the output:

I0606 16:07:06.307516 122123 so3_test.cc:30] using glog, sophus_R is:
00000.696364 000-0.707107 00000.122788
00000.696364 00000.707107 00000.122788
000-0.173648 -2.08167e-17 00000.984808
using std::cout, sophus_R is:
    0.696364    -0.707107     0.122788
    0.696364     0.707107     0.122788
   -0.173648 -2.08167e-17     0.984808

It seems glog will automatically fill '0' to the empty place before number. How can I make glog output format be same with std::cout(not fill 0)?

1

There are 1 best solutions below

0
On BEST ANSWER

It seems the glog stream's fill character has been set to 0. I suggest explicitly setting it back to a space, ' ' using std::setfill:

#include <iomanip>

LOG(INFO) << "using glog, sophus_R is:\n" << std::setfill(' ') << sophus_R.matrix();