给出以下代码:
std::string str;
str= std::regex_replace(str, std::regex("\r"), ""); // ERROR
我收到以下错误:
no matching function for call to ‘regex_replace(std::string&, std::regex, const char [1])’
如何解决此错误?
答案 0 :(得分:0)
**I've had this problem before.**
The following is the phenomenon that I test the same piece of code on different versions of G++.
### 1.code
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str="abc111abc222";
regex reg("abc");
string solve=regex_replace(str,reg,"");
cout<<solve<<endl;
return 0;
}
### 2.Test
#### (1)The origin of the problem:g++ version 4.8.1
Testing environment:
DevC++5.9.2
g++ version 4.8.1 (tdm64-2)
Whether to enable the c++11 option:
Yes.Turn on`-std=c++11`
Error:
`[Error] no matching function for call to 'regex_replace(std::string&, std::regex&, const char [1])'`
#### (2)g++ 6.5.0
Testing environment:
g++ 6.5.0
Output:`111222`
#### (3)clang++11
Testing environment:
In site of “nowcoder”
C++(clang++11)
Output:`111222`
### 3、The final solution:
We could choose a later version of the G++ compiler.