G++-5 tr1/regex regex_replace 无法解析
G++-5 tr1/regex regex_replace could not be resolved
我正在使用带有方言选项 -std=c++0x
和预处理器符号 __GXX_EXPERIMENTAL_CXX0X__
的 G++-5,我正在尝试使用 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
要回答这个问题:
用户 "Baum mit Augen" 通过说
解决了这个问题:
Alright, in tr1::regex you apparently need 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. – Baum mit Augen May 28 at 11:10
我正在使用带有方言选项 -std=c++0x
和预处理器符号 __GXX_EXPERIMENTAL_CXX0X__
的 G++-5,我正在尝试使用 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
要回答这个问题: 用户 "Baum mit Augen" 通过说
解决了这个问题:Alright, in tr1::regex you apparently need 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. – Baum mit Augen May 28 at 11:10