小智 18
也许如下:
if (std::string::npos != s.find_first_of("0123456789")) {
std::cout << "digit(s)found!" << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
boost::regex re("[0-9]");
const std::string src = "test 123 test";
boost::match_results<std::string::const_iterator> what;
bool search_result =
boost::regex_search(src.begin(), src.end(), what, re, boost::match_default);
Run Code Online (Sandbox Code Playgroud)
#include <cctype>
#include <algorithm>
#include <string>
if (std::find_if(s.begin(), s.end(), (int(*)(int))std::isdigit) != s.end())
{
// contains digit
}
Run Code Online (Sandbox Code Playgroud)