regex - 如何解决这个错误 “no matching function for call to ‘regex_replace..`?

标签 regex c++11 compiler-errors

给出以下代码:

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.

关于regex - 如何解决这个错误 “no matching function for call to ‘regex_replace..`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64058959/

相关文章:

c++ - 编译时的类型特化

sockets - 有人可以改善我的代码吗?怎么了?

c++ - 无法在 lambda 中捕获

c# - 为什么正则表达式替换方法不起作用?

java - 正则表达式匹配否定到 ebay 网站

C++11 访问具有限定名称的无作用域枚举数

c++ - std::unique_ptr 和 reset() 或您的类的 Reset 方法?

c - 为什么我可以在声明前使用结构类型的指针

JavaScript : Detect if a String contain url image

Java:每个字符出现0-1次的正则表达式