c++正则表达式老是初始化错误,用的gcc4.8

#include
#include
#include
using namespace std;

bool isNumeric(char* string)
{
std::string str;
if(string==NULL) return false;
while((*string)!='\0'){
str+=*string;
string++;
}

regex reg1("^[\\+-]?[0-9]+(\\.([0-9]+))?([Ee][\\+-]?[0-9]+)?$");
return regex_match(str,reg1);

}

int main(){
char string[20]="3.14";
cout<< isNumeric(string)<<endl;
return 0;
}图片说明

4.8里面对regex应该还没有支持,用5.0以上

。。。。。。运行结果是:1

gcc 4.8不支持std::regex。

升级gcc至4.9以上版本或者换用boost.regex.

gcc早期版本regex没有具体实现,后来才逐步加入。vs的话2013,2015逐步支持的比较好了