我使用G++-5和方言选项-std=c++0x和预处理符号__GXX_EXPERIMENTAL_CXX0X__,我试图使用tr1/regex。
我将#include <tr1/regex>与using namespace std::tr1;和regex reg("<[^>]*>");合并使用,没有错误。只有在之后使用regex_replace(line, reg, "");时,才会得到以下错误输出:
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包。
这个问题有解决办法吗?
编辑:
#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
发布于 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分
https://stackoverflow.com/questions/37497696
复制相似问题