RosettaCodeData/Task/Determine-if-a-string-is-numeric/C++/determine-if-a-string-is-numeric-1.cpp

12 lines
218 B
C++
Raw Permalink Normal View History

2024-04-19 16:56:29 -07:00
#include <cctype>
#include <cstdlib>
bool isNumeric(const char *s) {
if (s == nullptr || *s == '\0' || std::isspace(*s)) {
return false;
}
char *p;
std::strtod(s, &p);
return *p == '\0';
2023-07-01 11:58:00 -04:00
}