Regular expressions in C ++ STL

Is there a built-in library in STL that is tested and works without any additional compiler options? I tried using <regex> , but the compiler outputs this:

In the file included in / usr / include / c ++ / 4.3 / regex: 40, from main.cpp: 5: / usr / include / c ++ / 4.3 / c ++ 0x_warning.h: 36: 2: error : #error This file requires compiler and library support for the upcoming ISO C ++, C ++ 0x standard. This support is currently experimental and should be included with the options -std = C ++ 0x or -std = gnu ++ 0x.

+6
c ++ regex stl
source share
3 answers

g ++ 4.3 (and, presumably, later versions) simply takes care of the header files for maximum compliance.

If you are programming in C ++ 98 (the current standard that has been around for a while), regular expression support has been added to technical report 1, and the header files are in the special directory tr1 , and the contents are in the special namespace std::tr1 .

In the new C ++ 0x standard, regular expression support has been integrated into a standard library, so it can be found in the regex header and in the std .

g ++ ensures that you are using the correct version for the --std= version that you specified on the command line, although internally they represent the same implementation.

So, to make the regex work without switching to --std=c++0x , just

 #include <tr1/regex> 
+12
source share

I'm sure regular expression support has been added in C ++ 0x, so there are no STL things that support it until then. If you do not want to use C ++ 0x, you can use Boost instead, but this is not in the STL.

+5
source share

You can try using Boost.Regex instead of C ++ 0x headers.
Also STL is not the same as the standard library. This used to mean the "standard template library" when it was an SGI proposal. The standard library did not accept everything that was in STL (rope and slash), and covers much more land than STL (iostreams, all tr1, tr2 and C ++ 0x headers).

+3
source share

All Articles