gpt4 book ai didi

c++ - 将 C++11 regexp 与 gcc 4.8.2 一起使用时出现奇怪的结果(但适用于 Boost regexp)

转载 作者:可可西里 更新时间:2023-11-01 17:51:05 27 4
gpt4 key购买 nike

<分区>

我尝试使用 C++11 的正则表达式,但即使在简单的示例中也失败了。从外面看,它似乎只是比较字符串,例如:

std::regex_match(std::string{""}, std::regex{"a?"})   // false (???)
std::regex_match(std::string{"a?"}, std::regex{"a?"}) // true (???)

相比之下,Boost 的正则表达式库的行为符合我的预期:

boost::regex_match(std::string{""}, boost::regex{"a?"})   // true  (OK)
boost::regex_match(std::string{"a?"}, boost::regex{"a?"}) // false (OK)

我使用 GCC 4.8.2 和 clang 3.4(也使用 GCC 的 STL 库)进行了测试。要么库坏了,要么我不理解 C++11 标准定义的语法。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com