// A1_2.cpp #include #include #include #include using namespace std; template string concat(const string &s, T t) { ostringstream temp; temp << s.c_str() << " " << t << ends; return temp.str(); } /* template string concat(const string &s, const T &t) { char buffer[17]; string temp = s; if(typeid(t).name()==string("int")) { _itoa(t,buffer,10); temp += buffer; return temp; } if(typeid(t).name()==string("float") || typeid(t).name()==string("double")) { _gcvt(t,10,buffer); temp += buffer; return temp; } return ""; } */ void main() { string s1 = concat("this is an integer: ",-3); cout << "\n " << s1.c_str(); string s2 = concat("this is a double: ", 3.3333e-3); cout << "\n " << s2.c_str() << "\n\n"; }