首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >G++-5 tr1/regex regex_replace无法解析

G++-5 tr1/regex regex_replace无法解析
EN

Stack Overflow用户
提问于 2016-05-28 10:08:38
回答 1查看 217关注 0票数 0

我使用G++-5和方言选项-std=c++0x和预处理符号__GXX_EXPERIMENTAL_CXX0X__,我试图使用tr1/regex

我将#include <tr1/regex>using namespace std::tr1;regex reg("<[^>]*>");合并使用,没有错误。只有在之后使用regex_replace(line, reg, "");时,才会得到以下错误输出:

代码语言:javascript
复制
Function 'regex_replace' could not be resolved  test.cpp    /cppUni/src line 72 Semantic Error

Invalid arguments '
Candidates are:
#0 regex_replace(#0, #1, #1, const std::tr1::basic_regex<#3,#2> &, const ? &, std::bitset<unsigned long int11>)
? regex_replace(const ? &, const std::tr1::basic_regex<#1,#0> &, const ? &, std::bitset<unsigned long int11>)
'   test.cpp    /cppUni/src line 72 Semantic Error

我验证了,line是一个字符串。

在过去的几个小时里,我一直在寻找一个解决方案,并且只能找到与我所尝试的内容相关的解决方案。不幸的是,我不能使用boost/regex包。

这个问题有解决办法吗?

编辑:

代码语言:javascript
复制
#include <tr1/regex>
#include <iostream>
#include <string>

using namespace std;

int main(){
  std::tr1::regex reg("<[^>]*>");  
  string line = "<Day>22</Day>";

  if(line.find("<Day>") != string::npos)
    {
        line =std::tr1::regex_replace(line, reg, "");
        cout<<line<<endl;
    }
  return 0;
}

g++-5 -std=c++11 -D__GXX_EXPERIMENTAL_CXX0X__ -Wall test.cpp -o test.out

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-01 18:22:07

要回答这个问题:用户"Baum mit Augen“通过以下方式解决了这个问题:

好的,在tr1::regex中,您显然需要std::tr1::regex_replace(行,reg,字符串(“”));。(虽然这导致了Wandbox中的链接器错误,但可能他们只是没有安装遗留的东西,我不知道。)您应该只使用C++11中的std::regex,就像我在上面展示的那样,它工作得很好。- Baum mit Augen 5月28日11时10分

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37497696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档