I\'ve had quite a bit of trouble trying to write a function that checks if a string is a number. For a game I am writing I just need to check if a line from the file I am r
Brendan this
bool isNumber(string line)
{
return (atoi(line.c_str()));
}
is almost ok.
assuming any string starting with 0 is a number, Just add a check for this case
bool isNumber(const string &line)
{
if (line[0] == '0') return true;
return (atoi(line.c_str()));
}
ofc "123hello" will return true like Tony D noted.