i'm trying to create a complex software in C++ using Regular expressions... Now i'm doing some tests, but i've got runtime error. I tried gcc 4.7 on Ubuntu 12.04 64bit and latest CodeBlocks with compiler included (I think is MinGW porting of gcc 4.7). The Regular Expression is correct because i try that on this website http://gskinner.com/RegExr/ and work. They need to recognize and addition. This is the software:
#include <iostream>
#include <string>
#include <regex>
using namespace std;
string stringa;
int main()
{
cin >> stringa;
if (regex_match(stringa, regex("^[0-9]*\\+[0-9]*$", regex::ECMAScript))) //need to insert \\ to prevent escape sequence
{
cout << "Addition" << endl;
}
else
{
cout << "Not addition" << endl;
}
return 0;
}
When i run that, after insert input, i receive that error:
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error Annullato (core dump creato)
The problem is my code or compiler?