Skip to content

Instantly share code, notes, and snippets.

@AhiyaHiya
Last active November 18, 2016 18:38
Show Gist options
  • Save AhiyaHiya/30d2535f11a300c369337eb39c88e685 to your computer and use it in GitHub Desktop.
Save AhiyaHiya/30d2535f11a300c369337eb39c88e685 to your computer and use it in GitHub Desktop.
/*
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