Using * Width & Precision Specifiers With boost::format

Posted by John Dibling on Stack Overflow See other posts from Stack Overflow or by John Dibling
Published on 2010-06-04T22:03:38Z Indexed on 2010/06/05 9:52 UTC
Read the original article Hit count: 153

Filed under:
|

I am trying to use width and precision specifiers with boost::format, like this:

#include <boost\format.hpp>
#include <string>

int main()
{
    int n = 5;
    std::string s = (boost::format("%*.*s") % (n*2) % (n*2) % "Hello").str();
    return 0;
}

But this doesn't work because boost::format doesn't support the * specifier. Boost throws an exception when parsing the string.

Is there a way to accomplish the same goal, preferably using a drop-in replacement?

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost