stringstream << version of sprintf with variable precision?
I would like to rewrite something like
Code:
sprintf(str, "%d, %.1lf, %.3lf, %.2lf, ...", a, b, c, d, ....)
to something like
Quote:
stringstream str<<a<<fixed<<b<<c<<d ...
But is there a way to specify varying precision easily (there are about 100 values to be converted to a string with varying precisions.)? Something like
Code:
... <<%.1<<b<<%.3<<c<<%.2<<d ...
Possible? If so then what's the syntax? Thanks!
Re: stringstream << version of sprintf with variable precision?
You could look into Boost.Format.
Re: stringstream << version of sprintf with variable precision?
setprecision() may help. Consider to include <iomanip>.