gpt4 book ai didi

c++ - c++ 中的正则表达式编译错误

转载 作者:搜寻专家 更新时间:2023-10-31 01:02:35 27 4
gpt4 key购买 nike

我正在和某人一起做一个项目,我们有完全相同的代码,但是他的代码可以编译,而我的代码继续抛出错误。这是我的代码:

bool r_parser::parseMake(string name, string command, string type, string val)
{
regex regName("^\\w+$");
if(std::regex_match(name, regName) == true)
{
cout << "We have a match!" << endl;
}
return false;
}

这是我遇到的错误:

'undefined reference to std::basic_regex<char, std::regex_traits<char> >::_M_compile()'

'undefined reference to bool std::regex_match<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<std::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, char, std::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, std::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<std::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, std::basic_regex<char, std::regex_traits<char> > const&, std::bitset<11u>)'

自从我伙伴的代码编译后我们找不到我的代码有什么不同,我想知道是否有人可以阐明这种情况。

感谢您的宝贵时间。

编辑:我忘了说我有:

#include <regex>
#include <string>
#include <iostream>
using namespace std;

在我的头文件中。

最佳答案

迈克尔,我做了更多研究,看来 #include <regex>only a placeholder until GCC version 4.9.0.

如果您使用的是 Windows 系统(我记得您是这样的),您正在通过 MinGW 使用 GCC,因此您需要手动更新到最新版本。我在 4.9.1,这就是它对我有用的原因。 You can download that from Sourceforge.

如果您使用的是 Linux,您应该能够通过存储库更新 gcc 和 g++。

如果不想更新,也可以用the Boost libraries .但是,我建议更新您的编译器,主要是因为使用您正在实现的任何编译器的最新版本通常是一个好主意,除非您有明确的理由不这样做。

抱歉,我之前无法回答这个问题,但希望对您有所帮助!

关于c++ - c++ 中的正则表达式编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26921840/

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