/*************************************************************************** DESCRIPTION Some template functions that translate different types to strings. Useful for creating error messages and the like. AUTHOR Mike Smoot ***************************************************************************/ #ifndef TOSTRING_H #define TOSTRING_H #include #include #include //----------------------------------------------------------------------- // ztos - zero padded T to string - useful for ints, floats, etc. // template string ztos(const T& t, const int& numDigits, const int& num=3 ) { ostrstream os; os << setprecision(num) << setiosflags(ios::showpoint|ios::fixed) << t << ends; string s(os.str()); os.rdbuf()->freeze(0); while (s.length() < (unsigned)numDigits) s = "0" + s; return s; } /* ** ** Copyright (C) 2000 Gustavo Niemeyer ** ** http://projects.nn.com.br/ ** */ //----------------------------------------------------------------------- // Type T to string. // // Originally from Gustavo Niemeyer but modified by me. // This code was found on sourceforge.net in the C++ snippets section. // template string tos(const T& _t, const int& num=2) { ostrstream os; os << setprecision(num) << setiosflags(ios::showpoint|ios::fixed) << _t << ends; string s(os.str()); os.rdbuf()->freeze(0); return s; } #endif