i haven't ran it yet or anything, but the idea is to take a string and convert it into type int, float, long, or long double.
would anyone implement this differently?...
Code:
template<class NumberType> NumberType parse(const char &stringOfNumbers)
{
//some parsing algorithm
//isn't there a header with these defintions?
NumberType convertedNumber;
int sizeFloat = sizeof(float);
int longSize = sizeof(long);
int longdoubleSize = sizeof(long double);
switch(sizeof(NumberType))
{
case floatSize:
convertedNumber = atof(stringOfNumber, 10); //stringOfNumbers = "1234.54"
break;
case longSize:
convertedNumber = atol(stringOfNumbers, 10);
break;
//.....................
}
}