- 论坛徽章:
- 0
|
- #include <regex>
- #include <iostream>
- #include <string>
- using namespace std;
- int main(int argc,char* argv[])
- {
- string str;
- regex reg("(\\+|-)?[[:digit:]]+",regex_constants::extended);
- cin>>str;
- while(str!="q")
- {
- if(regex_match(str,reg))
- {
- cout<<"Num:"<<str<<endl;
- }
- else
- {
- cout<<"Not num: "<<str<<endl;
- }
- cin>>str;
- }
- return 0;
- }
复制代码 编译没问题:
g++ -g -Wall -std=c++11 test_regex.cpp
运行错误:
./a.out
- terminate called after throwing an instance of 'std::regex_error'
- what(): regex_error
- Aborted (core dumped)
复制代码 什么情况啊? |
|