std::string 字符串替换

std::string 没有原生的字符串替换函数,需要自己来完成

 1 string& replace_str(string& str, const string& to_replaced, const string& newchars)     
 2 {
 3     for(string::size_type pos(0); pos != string::npos; pos += newchars.length())   
 4     {
 5         pos = str.find(to_replaced,pos);
 6         if(pos!=string::npos)     
 7            str.replace(pos,to_replaced.length(),newchars);     
 8         else  
 9             break;  
10     }     
11     return   str;     
12 }
原文地址:https://www.cnblogs.com/tyche116/p/9593309.html