Using * Width & Precision Specifiers With boost::format
- by John Dibling
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?