C++ – How to test if a string contains any digits in C++

cstring

I want to know if a string has any digits, or if there are no digits. Is there a function that easily does this?

Best Answer

Perhaps the following:

if (std::string::npos != s.find_first_of("0123456789")) {
  std::cout << "digit(s)found!" << std::endl;
}