N
nvangogh
Icompiled this program after reading the code from C++ Primer 5th Edition
page 729. I used the C++11 standard flag on the gcc 4.7 compiler. The
program compiles without any problems:
code:
#include <iostream>
#include <regex>
#include <string>
int main()
{
std::string pattern("[^c]ei");
pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
std::regex r(pattern);
std::smatch results;
std::string test_str = "receipt freind theif receive";
if(std::regex_search(test_str, results, r))
std::cout << results.str() << std::endl;
return 0;
}
-----------
When I run the program I get:
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
Abort trap (core dumped)
----------------
I have tried this program with exception handling to try and find out
more about the error, but all I got was error signal 4. I know that the
regex class uses ECMAscript as default and that this is tested at
runtime. Unfortunately, I cannot see what the problem is.
page 729. I used the C++11 standard flag on the gcc 4.7 compiler. The
program compiles without any problems:
code:
#include <iostream>
#include <regex>
#include <string>
int main()
{
std::string pattern("[^c]ei");
pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
std::regex r(pattern);
std::smatch results;
std::string test_str = "receipt freind theif receive";
if(std::regex_search(test_str, results, r))
std::cout << results.str() << std::endl;
return 0;
}
-----------
When I run the program I get:
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
Abort trap (core dumped)
----------------
I have tried this program with exception handling to try and find out
more about the error, but all I got was error signal 4. I know that the
regex class uses ECMAscript as default and that this is tested at
runtime. Unfortunately, I cannot see what the problem is.