help with this problem please

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.
 
M

Melzzzzz

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.

Problem is that regex implementation in gcc's libstdc++ is not complete,
therefore exception.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top