c ++ STL中的正则表达式 [英] Regular expressions in c++ STL
问题描述
STL中有没有任何本地库经过测试和工作没有任何额外的编译器选项?
我尝试使用< regex>
,但编译器输出:
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:
从/usr/include/c++/4.3/regex:40,从main.cpp:5:
/usr/include/c++/4.3/c++0x_warning.h:36:2:error:#error这个文件需要编译器和库支持即将到来的ISO C ++标准C ++ 0x。此支持目前是实验性的,必须使用-std = c ++ 0x或-std = gnu ++ 0x编译器选项启用。
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.
推荐答案
G ++ 4.3(以及推测更新的版本)只是为了达到最大的标准符合性而仔细考虑头文件。
G++ 4.3 (and presumably later versions as well) is just being careful about the header files for maximum standards conformance.
++ 98(当前标准已经存在了一段时间),然后在技术报告1中添加了正则表达式支持,并且头文件位于特殊的 tr1
目录,并且内容在特殊的命名空间 std :: tr1
。
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
.
在新的C ++ 0x标准,正则表达式支持已经被合并到标准库中,因此可以在 regex
和命名空间 std
。
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 ++确保您为您指定的 - 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.
因此,为了使正则表达式不需要切换到 - std = c + + 0x
,只是
So to make regex work without switching to --std=c++0x
, just
#include <tr1/regex>
这篇关于c ++ STL中的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!