我'm trying to utilize the ' TR1 ' regular expression extensions for some C++ string parsing. I'已读到 <regex>
标头和命名空间std :: tr1是必需的
我可以使用 <regex>
标头进行编译(虽然它强制我使用标志, -std=c++0x
或 -std=gnu++0x
)
但是,当我尝试在程序中使用 std::tr1
命名空间时,编译失败并显示消息tr1 "is not a namespace name" . 我不能做的事情,
std::tr1::regex rx("mypattern");
我已经读过自gcc 4.3.0以来支持TR1正则表达式 . 我通过gcc 4.4.5使用g .
我错过了什么吗?
1 回答
g++ 4.7 doesn't implement regular expressions yet.
但尽管如此,在C 11中
regex
已从命名空间std::tr1
移至std
. 所以,而不是std::tr1::regex
,你应该写std::regex
:我不知道4.7之前的哪个g版本也适用 . 但this ideone example用g 4.7编译好 . 但是,请记住,此编译器版本中未实现正则表达式实现 .