gpt4 book ai didi

c++ - C++ 中的正则表达式 : Requires compiler support error

转载 作者:太空狗 更新时间:2023-10-29 19:53:27 26 4
gpt4 key购买 nike

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

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

但是我遇到了这个错误:

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.

这个怎么解决,哪里出了问题?

最佳答案

and must be enabled with the -std=c++0x or -std=gnu++0x compiler options

将其中一个选项 -std=c++0x-std=gnu++0x 添加到您的编译器命令中:

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

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

关于c++ - C++ 中的正则表达式 : Requires compiler support error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13836898/

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