c++ - Is there a quick way to check if a string is numeric? -
is possible check if string variable entirely numeric? know can iterate through alphabets check non-numeric character, there other way?
the quickest way can think of try cast "strtol" or similar functions , see whether can convert entire string:
char* numberstring = "100"; char* endptr; long number = strtol(numberstring, &endptr, 10); if (*endptr) { // cast failed } else { // cast succeeded }
this topic discussed in thread: how determine if string number c++?
hope helps :)
Comments
Post a Comment