C++ 正则表达式判断字符串是否为数字

180it 2020-10-13 PM 2799℃ 0条
#include <iostream>
using namespace std;
#include <regex>
regex r(R"(^^\s*[-+]?((\d+(\.\d+)?)|(\d+\.)|(\.\d+))(e[-+]?\d+)?\s*$)");

class Solution {
public:
    bool isNumber(const string& s) {
        return regex_match(s, r);
    }
};

int main()
{

    system("chcp 65001");

    Solution isnuma;

  if  (isnuma.isNumber("10A")==true)
  {      cout << "是Number" << endl;
}else{
cout << "不是Number"  << endl;
}

    return 0;
}

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

C++ 正则表达式判断字符串是否为数字