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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…