简体   繁体   English

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

[英]G++-5 tr1/regex regex_replace could not be resolved

I am using G++-5 with the dialect option -std=c++0x and the preprocessor symbol __GXX_EXPERIMENTAL_CXX0X__ and I am trying to use the tr1/regex . 我将G ++-5与方言选项-std=c++0x和预处理器符号__GXX_EXPERIMENTAL_CXX0X__一起使用,并且尝试使用tr1/regex

I use #include <tr1/regex> with using namespace std::tr1; 我使用#include <tr1/regex>using namespace std::tr1; and regex reg("<[^>]*>"); regex reg("<[^>]*>"); trows no error. 没有错误。 Only when I use regex_replace(line, reg, ""); 仅当我使用regex_replace(line, reg, ""); afterwards, I get the following error output: 之后,我得到以下错误输出:

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

I verified, that line is a String. 我确认,那条line是一个字符串。

I searched for a solution the last couple of hours and could only find solutions that involved what I attempted. 我在最近几个小时内寻找解决方案,但只能找到涉及我尝试的解决方案。 Unfortunately I can't use the boost/regex package. 不幸的是,我不能使用boost/regex软件包。

Is there a solution for this issue? 这个问题有解决方案吗?

EDIT: 编辑:

#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

To have this answered: User "Baum mit Augen" solved the issue by saying: 要回答这个问题,用户“ Baum mit Augen”通过说出了这一问题来解决了:

Alright, in tr1::regex you apparently need std::tr1::regex_replace(line, reg, string(""));. 好了,在tr1 :: regex中,您显然需要std :: tr1 :: regex_replace(line,reg,string(“”)));。 (Though that resulted in a linker error in Wandbox, but maybe they just don't have that legacy stuff installed, I dunno.) You should just use std::regex from C++11 instead, it works fine as I showed above. (尽管这会导致Wandbox中出现链接器错误,但我不知道它们可能没有安装旧版内容,)您应该只使用C ++ 11中的std :: regex,如上所示,它可以正常工作。 – Baum mit Augen May 28 at 11:10 – Baum mit Augen 5月28日11:10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM