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

前端 未结 6 1559
日久生厌
日久生厌 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:40

    boost::regex re("[0-9]");
    const std::string src = "test 123 test";
    boost::match_results what; 
    bool search_result = 
       boost::regex_search(src.begin(), src.end(), what, re, boost::match_default);
    

提交回复
热议问题