Нет ничего стандартного для этой цели, но его нетрудно сделать:
template <typename CharT>
bool has_digits(std::basic_string<CharT> &input)
{
typedef typename std::basic_string<CharT>::iterator IteratorType;
IteratorType it =
std::find_if(input.begin(), input.end(),
std::tr1::bind(std::isdigit<CharT>,
std::tr1::placeholders::_1,
std::locale()));
return it != input.end();
}
И вы можете использовать его так:
std::string str("abcde123xyz");
printf("Has digits: %s\n", has_digits(str) ? "yes" : "no");
Редактировать:
Или даже лучше версия (поскольку она может работать с любым контейнером, как с const, так и с неконстантными контейнерами):
template <typename InputIterator>
bool has_digits(InputIterator first, InputIterator last)
{
typedef typename InputIterator::value_type CharT;
InputIterator it =
std::find_if(first, last,
std::tr1::bind(std::isdigit<CharT>,
std::tr1::placeholders::_1,
std::locale()));
return it != last;
}
А этот вы можете использовать как:
const std::string str("abcde123xyz");
printf("Has digits: %s\n", has_digits(str.begin(), str.end()) ? "yes" : "no");