C++中的Regex:需要编译器支持错误

Eni*_*man 3 c++ regex compiler-construction

我正在尝试regex在C++中使用.以下是我的代码:

#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<regex>
using namespace std;

int main(int argc, char** argv) {
    string A = "Hello!";
    regex pattern = "(H)(.*)";
    if (regex_match(A, pattern)) {
        cout << "It worked!";
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是我遇到了这个错误:

In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/regex:35:0,
                 from main.cpp:12:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

hmj*_*mjd 6

并且必须使用-std = c ++ 0x或-std = gnu ++ 0x编译器选项启用

添加其中一个选项,-std=c++0x或者-std=gnu++0x,添加到编译器命令:

g ++ -std = c ++ 0x ...

请注意,如果std::regex不支持,请参阅boost::regex替代方案.