C++ 使用C++;正则表达式库

C++ 使用C++;正则表达式库,c++,regex,c++11,C++,Regex,C++11,regex_搜索函数的性能与预期不太一样 #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)

regex_搜索函数的性能与预期不太一样

#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;
}

<> P>在对问题的评论中指出,C++标准库的旧实现还没有支持C++ 11中的所有特性。当然,这是一个例外,因为它最初是专门为C++11构建的

根据libstdc++中对
的支持,它只在GCC的4.9版本中实现。您可以在上检查当前状态


您可以确认,您的示例在GCC4.9上运行,但在GCC4.8上仍然失败。

请记住,C++11是非常新的,并且并非所有编译器都支持所有功能。特别是,谢谢你指出这一点。我想我现在就去看看Boost的正则表达式库。@wenderen:如果你想避免构建Boost(Xpressive只是头文件,不像正则表达式),一定要看看Boost.Xpressive而不是Boost.regex。@JoachimPileborg那么gcc对这个奇怪的东西有什么意图呢?如果
std::regex_search
函数不起作用,为什么还要公开它呢(他的例子并不是真正的边缘案例)?我宁愿错过这个函数,也不愿在它不起作用的时候使用它。@ChristianRau我不知道GCC的设计者是怎么想的,但我猜最好有一个完整的界面,即使界面背后的一些实际功能缺失了。
0