Is there any native library in STL which is tested and works without any extra compiler options?
I tried to use <regex>
, but the compiler outputs this:
In file included from /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++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
<regex> library in C++ STL These classes encapsulate a regular expression and the results of matching a regular expression within a target sequence of characters. These functions are used to apply the regular expression encapsulated in a regex to a target sequence of characters.
It is used in every programming language like C++, Java, and Python. Used to find any of the characters or numbers specified between the brackets. Used to find any digit.
[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9.
A simple example for a regular expression is a (literal) string. For example, the Hello World regex matches the "Hello World" string. . (dot) is another example for a regular expression. A dot matches any single character; it would match, for example, "a" or "1".
G++ 4.3 (and presumably later versions as well) is just being careful about the header files for maximum standards conformance.
If you're programming in C++98 (the current standard that's been around for a while), then regular expression support was added in tech report 1, and the and the header files are in a special tr1
directory, and the contents are in a special namespace std::tr1
.
In the new C++0x standard, the regular expression support has been merged into the standard library, so it can be found in the header regex
and namespace std
.
G++ makes sure that you use the right version for the --std=
version you specified on the command line, even though internally they're both the same implementation.
So to make regex work without switching to --std=c++0x
, just
#include <tr1/regex>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With