I am trying to use width and precision specifiers with boost::format
, like this:
#include <boostformat.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?
See Question&Answers more detail:os