/////////////////////////////////////////////////////////// // MT1Q7 - Convert instance of arbitrary type to string // // // // Jim Fawcett, CSE687 - OOD Midterm, Spring 2018 // /////////////////////////////////////////////////////////// #include #include #include "../MTutility/MTutility.h" template std::string ToString(const T&t) { std::ostringstream conv; if(typeid(t).name() == typeid(double).name()) conv.precision(10); conv << t; return conv.str(); } int main() { Title("MT1Q7 - ToString Conversion"); std::string pi = ToString(3.14159265); std::cout << "\n " << pi << " has " << pi.size() << " characters"; std::string ten = ToString(10); std::cout << "\n " << ten << " has " << ten.size() << " characters"; std::cout << "\n\n"; }