如何解决如何解决此错误“没有匹配的函数来调用regex_replace ..”?
给出以下代码:
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])’
如何解决此错误?
解决方法
**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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。