Showing posts with label cplusplus. Show all posts
Showing posts with label cplusplus. Show all posts

Wednesday, August 13, 2014

How to use Regex with GCC 4.8.2

How to use Regex with GCC 4.8.2

My setup:

Operation system: Ubuntu 14.04
Compiler: GCC 4.8.2
IDE: Eclipse 3.8.1

Problem:

I've included regex (#include <regex>) to my header file but my IDE keeps complaining that type of 'something' could not be resolved. I've tried using namespaces such as std:: and std::tr1, like people from google has adviced, with no success.

Solution:

Solution is as simple as the problem itself. If you take a look at usr/include/c++/4.8 you'll notice the regex file in root folder is kind of a stub. However there's another regex file in /tr1 folder.

The trick is, that instead of writing #include <regex>, you should write #include <tr1/regex>

After that you're able to use regex through std::tr1:: namespace.

For exmaple like this: std::tr1::smatch

Hope that helps!