跳转到帖子
登录关注  
墨香年少

c++判断字符串是不是数字

已推荐帖子

#include <iostream>
#include <string>
#include <algorithm>
 
bool is_numeric(std::string const &str)
{
    auto it = std::find_if(str.begin(), str.end(), [](char const &c) {
        return !std::isdigit(c);
    });
 
    return !str.empty() && it == str.end();
}
 
int main()
{
    std::string str = "1234567890";
 
    std::cout << std::boolalpha << is_numeric(str) << std::endl;        // true
 
    return 0;
}

 

  • 有帮助 1

目之所及,皆是回忆,心之所想,皆是过往

分享这篇帖子


链接帖子
分享到其他站点

创建帐户或登录来提出意见

你需要成为会员才能提出意见

创建帐户

注册成为会员。只要几个简单步骤!

注册帐户

登录

已有帐户? 请登录。

现在登录
登录关注  

×
×
  • 创建新的...

重要信息

注册必须使用2-8个中文汉字作为账号