2

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

这是怎么回事?

4

1 回答 1

1

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

根据此错误报告<regex>,仅在 GCC 4.9 版中实现了对 libstdc++ 的支持。您可以在libstdc++ 状态页面上查看当前状态。

可以确认,您的示例适用于 GCC 4.9,但仍然无法使用 GCC 4.8。

于 2016-04-05T13:42:02.617 回答