12345678910111213141516171819202122232425
#include <sstream> #include <string> template <typename ValueType> std::string stringify( const ValueType& value, int width = 0, int precision = 0, ios_base::fmtflags flags = 0, char fillchar = 0 ) { ostringstream ss; if (width > 0) ss.width( width ); if (precision > 0) ss.precision( precision ); if (flags != 0) ss.flags( flags ); if (fillchar != 0) ss.fill( fillchar ); ss << value; return ss.str(); } int main() { float f = 12.7; string s = stringify( f, 0, 0, ios::fixed ); cout << s << endl; return 0; }