void deletesub(string &str,const string &sub,int n) { int m,flag=0,num=0; //num是子串出现的次数 while(flag==0) { m=str.find(sub);//在str中找子串sub,返回起点下标 if(m<0)//没找到 flag=1; else { str.erase(m,n);//删除子串,起点和sub长度 num++; } } cout<<str<<endl;// 输出删除后的字符串 }
作者:海哥哥
Github:https://github.com/jasonhavenD