【问题标题】:'regex' type not recognized“正则表达式”类型无法识别
【发布时间】:2016-05-25 21:54:45
【问题描述】:

我遇到了一个奇怪的问题。 首先,这是我的代码:

#ifndef REGEX_H
#define REGEX_H

#include <regex>

/******************************  REGEX  *************************/
class MyRegex {
 regex reg;
 StrategieLitteraux* strategie;

public :
 MyRegex(regex _reg, StrategieLitteraux* _strategie) : reg(_reg), strategie(_strategie) {}
 virtual ~MyRegex() {}
 void execute(Pile& pile,const QString& s) { strategie->execute(pile,s); }
 regex getRegex() const {return reg;}

};
/*******************************************************************/
#endif // REGEX_H

我收到了这个错误:

'regex' 没有命名类型

我不知道我做错了什么。有谁有想法吗 ?我以前已经使用过正则表达式,但这次我无法让它工作。谢谢

【问题讨论】:

  • 你需要std::regex
  • 您正在寻找std::regex。附:我要祝贺你避免了名为“using namespace std;”的令人讨厌的癌症。
  • 谢谢!我在 Qt 上,看起来我什至不需要 std::regex。我只需要包含“strategie.h”,它就可以识别正则表达式。我不知道为什么,但如果我遇到这个错误,我会使用 std::regex :) 编辑:实际上我知道,strategie.h 包括 computer.h,它使用“使用名称 std”。我将删除这一行。

标签: c++ regex


【解决方案1】:

regexstd 命名空间的一部分。您需要使用std::regex

【讨论】:

  • 谢谢 :) 见我上面的评论。
  • @Chuck 您的问题并未反映您在该评论中表达的问题。您应该编辑您的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-04
  • 2023-01-16
  • 2017-12-08
  • 1970-01-01
相关资源
最近更新 更多