A
Alex Neumann
Hi,
I need a function which converts an string to an integer.
Currently I have this:
bool string2int(char* digit, int& result)
{
result = 0;
if (!(*digit >= '0' && *digit <='9'))
return false;
while (*digit >= '0' && *digit <='9')
{
result = (result * 10) + (*digit - '0');
digit++;
}
if (*digit != 0 && *digit != ',' && *digit != ']')
{
return false;
}
return true;
}
Has someone a better idea ?
Only ISO C++ please, no extra libs ;-)
Thanks...
I need a function which converts an string to an integer.
Currently I have this:
bool string2int(char* digit, int& result)
{
result = 0;
if (!(*digit >= '0' && *digit <='9'))
return false;
while (*digit >= '0' && *digit <='9')
{
result = (result * 10) + (*digit - '0');
digit++;
}
if (*digit != 0 && *digit != ',' && *digit != ']')
{
return false;
}
return true;
}
Has someone a better idea ?
Only ISO C++ please, no extra libs ;-)
Thanks...