如何测试一个字符串是否包含C ++中的任何数字 [英] How to test if a string contains any digits in C++

查看:152
本文介绍了如何测试一个字符串是否包含C ++中的任何数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道字符串是否有任何数字,或者没有数字。

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

推荐答案

也许是下面这些:

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

这篇关于如何测试一个字符串是否包含C ++中的任何数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆