I’m currently learning C++ and i run into the simple problem of converting an int to a string. I’ve worked around it using:
string IntToString(int Number)
{
stringstream Stream;
Stream << Number;
return Stream.str();
}
but though it would be more elegant to use something like:
int x = 5;
string y = x.toString();
but how do i add the toString() method to a built in type?
or am i missing something totally fundamental?
I would not derive any class from basic_string/string. This is not recommended and no method in string is virtual, it does not have a virtual destructor (hence deriving could reault in memory leaks)
Make it pretty for yourself:
You could create a static class (class containing only static methods) in order keep it all in the one place. Use method overloading for int, float, double, etc.