方法一:
string& replace_all(string& str,const string& old_value,const string& new_value) { while(true) { string::size_type pos(0); if( (pos=str.find(old_value))!=string::npos ) str.replace(pos,old_value.length(),new_value); else break; } return str; }
方法二:
string& replace_all(string& str,const string& old_value,const string& new_value) { while(true) { string::size_type pos(0); if( (pos=str.find(old_value))!=string::npos ) { //str.replace(pos,old_value.length(),new_value); str.erase(pos, old_value.length()); str.insert(pos, new_value); } else break; } return str; }