#include <string>
#include <iostream>
using namespace std;
namespace{
/// C-style format strings for various built-in types. Only allowed for
//// certain types, for which this function is explicitly specialized below.
template<typename T> inline const char *FmtString(T);
// Not implemented to prevent accidents with irregular meaning of argument:
// template<> inline const char *FmtString(const char *&) { return "%s"; }
// Convert object of built-in type to string
template<typename T> inline std::string ToString(const T &Obj)
{
// TODO: Find a decent way to determine max string length at compile time!
char Buf[500];
sprintf(Buf, FmtString(Obj), Obj);
return std::string(Buf);
}
}
int main(int argc,char *argv[])
{
int i= 1234;
string str = ToString(i);
cout<<str<<endl;
}