Last active
November 18, 2016 18:38
-
-
Save AhiyaHiya/30d2535f11a300c369337eb39c88e685 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Losely based on http://stackoverflow.com/questions/18154630/c-see-if-argument-is-numeric | |
and other related answers on stackoverflow.com | |
*/ | |
auto IsNumber(const std::string& maybeNumber) -> bool | |
{ | |
auto decimal = false; | |
for (char c : maybeNumber) | |
{ | |
if (c == '.' && !decimal) | |
decimal = true; | |
else if (c == '-') | |
continue; | |
else if (!std::isdigit(c)) | |
return false; | |
} | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment