formated cout of Eigen-vectors of int with Boost format

Viewed 359

I would like to cout Eigen-vectors of int using the boost::format such that the numbers are right-aligned. So far I have the following code

int main(){ 
vector<Vector3i> foo; Vector3i bar;

bar << -1,-1,0; foo.push_back(bar);
bar <<  0, 0,0; foo.push_back(bar);

boost::format header("%3d");

for (int i = 0; i < 2; ++i)
    cout << header % foo[i].transpose() << endl;

return 0;
}

and the output is

-1 -1  0
0 0 0

But I'm wishing to have the following output

-1 -1  0
 0  0  0

I could achieve the wanted result if I modified the format and the code inside the for with the following

boost::format header2("%2d %2d %2d");
for (int i = 0; i < 2; ++i) 
    cout << header2 % foo[i](0) % foo[i](1) % foo[i](2) << endl;

But, could someone tell me if there is a more efficient way to do this using boost::format?

1 Answers
Related