#include<windows.h>
#include<regex>
#include<iostream>
#include<string>
using namespace std;
string str="^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$";
regex re(str);
bool retMatchStr=false;
// regex re1(str1);
//bool retMatchStr1=false;
int main()
{
string numberstr="1";
retMatchStr=regex_match(numberstr,re);
if(!retMatchStr)
{
cout<<"数字错误";
}
else
{
/*str="^\d{1,8}(\.\d{1,8})?$";
bool retMatchStr=false;
regex re(str);
retMatchStr=regex_match(numberstr,re);
if(!retMatchStr)
{
cout<<"数字超过八位!!";
}
else
{
*/
cout<<"数字形式正确!!";
}
Sleep(80000);
return 0;
}
判断一个字符串是数字(正数 负数 小数)
最新推荐文章于 2023-04-03 18:18:53 发布