"std :: regex" since C ++ 11

I am trying to use the C ++ standard regex library. But it throws a std :: regex_error exception. I don't know what's going on. I can use Boost regex or PCRE.

But I was thinking that there is a regex module provided with g ++. But not being able to make it work even with simple expressions. Don't worry about unused variables, I started with a moderately complex expression they needed. But now I have reduced it to fit the word.

Please check the sample that crashes here:

http://ideone.com/fork/58EV7v

#include <iostream>
#include <stdio.h>
#include <regex>

int main()
{
    const char *vals = "abcdef";
    unsigned long start;
    unsigned int off;
    unsigned int size;

    std::cmatch cr;
    std::regex rx("(\\w+)");
    std::regex_match(vals, cr, rx);
    std::cmatch::iterator it = cr.begin();
    while (it != cr.end()){
        std::cout << *it << std::endl;
        ++it;
    }

    return 0;
}

      

+3


source to share





All Articles