wenderen
wenderen

Reputation: 171

Using regex_search from the C++ regex library

The regex_search function isn't quite behaving as expected.

#include <iostream>
#include <regex>
#include <string>

using namespace std;

int main()
{
    string str = "Hello world";
    const regex rx("Hello");
    cout << regex_search(str.begin(), str.end(), rx) << endl;
    return 0;
}

The output is

0

What's going on?

Upvotes: 2

Views: 570

Answers (1)

jotik
jotik

Reputation: 17920

As pointed out in comments to the question, older implementations of the C++ standard libraries did not yet support all features in C++11. Of course, libc++ being an exception because it was originally built specifically for C++11.

According to this bug report support for <regex> in libstdc++ was only implemented for version 4.9 of GCC. You can check the current status on the libstdc++ status page.

One can confirm, that your example works with GCC 4.9 while still failing with GCC 4.8.

Upvotes: 1

Related Questions