1

Possible Duplicate:
C++0x regex in GCC

I was trying to transform a file under c++ using regex, some regex_error keeps on occuring, here is the code:

std::ifstream inf(in);
std::ofstream outf(out);
try{
std::regex line_regex("[[:alnum:]]");
std::string line;
while(std::getline(inf,line))
{
    if(std::regex_match(line,line_regex))
        outf<<line<<std::endl;
}

the error message is:

terminate called after throwing an instance of 'std::regex_error'
what():  regex_error

by the way, I'm using gcc 4.7.2 on linux x64.

2
  • 2
    gcc version 4.6.1 had only partial support for std::regex, I don't know if it has been fixed in version 4.7.0 yet, on second thought I think they haven't fixed it check for regex in here gcc.gnu.org/onlinedocs/libstdc++/manual/… Commented Dec 16, 2012 at 7:13
  • I tried std::regex on 4.6.2 and couldn't get it to work either. Ended up wrapping PCRE instead. I think the Perl regex syntax is the best and most expressive and PCRE is an extremely stable time-honored library. Commented Dec 16, 2012 at 8:42

1 Answer 1

5

GCC's implementation of <regex> is unusable. Don't waste your time on it.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes,I use the boost version instead, it works fine.
@flyingfoxlee - as does the Microsoft version.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.