gpt4 book ai didi

c++ - 使用 C++ 正则表达式库中的 regex_search

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:30:56 26 4
gpt4 key购买 nike

regex_search 函数未按预期运行。

#include <iostream>
#include <regex>
#include <string>

using namespace std;

int main()
{
string str = "Hello world";
const regex rx("Hello");
cout << regex_search(str.begin(), str.end(), rx) << endl;
return 0;
}

输出是

0

这是怎么回事?

最佳答案

正如问题评论中所指出的,C++ 标准库的较旧实现尚不支持 C++11 中的所有功能。当然,libc++是一个异常(exception),因为它最初是专门为 C++11 构建的。

根据 this bug report支持<regex>在 libstdc++ 中仅针对 GCC 4.9 版实现。您可以在 libstdc++ status page 上查看当前状态.

可以确认,您的示例适用于 GCC 4.9,但在使用 GCC 4.8 时仍然失败。

关于c++ - 使用 C++ 正则表达式库中的 regex_search,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12279869/

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