I implemented the accepted answer to this question which uses std::isdigit
:
#include <string>
#include <ctype.h>
using namespace std;
bool is_number(const std::string& s)
{
std::string::const_iterator it = s.begin();
while (it != s.end() && std::isdigit(*it)) ++it;
return !s.empty() && it == s.end();
}
It works fine on Mac OS X. However when using MSVC in VS17 Professional 15.9.3 for Windows 10, I get this compiler error:
C2672 'std::isdigit': no matching overloaded function found.
I am porting code and KNOW this works on Mac OS X and clang. I have included <string>
, <cctype>
, <ctype.h>
and <stdlib.h>
nothing helps.
It makes no sense to me.