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

前端 未结 6 1555
日久生厌
日久生厌 2020-12-11 05:49

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

6条回答
  •  伪装坚强ぢ
    2020-12-11 06:36

    #include 
    #include 
    #include 
    
    if (std::find_if(s.begin(), s.end(), (int(*)(int))std::isdigit) != s.end())
    {
      // contains digit
    }
    

提交回复
热议问题