fork download
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. int main(){
  6. std::string str ("/home/docs/awp/awp/3/5/1/awp_awp.ch_20110504_1351_1-1351.html /home/docs/awp/awg/6/9/1/awp_awp.ch_20130404_691_1-691.xml /home/docs/awp/awp/6/9/1/awp_awp.ch_20130404_691_1-691.xml /home/docs/awp/awp/6/9/1/awp/awp.ch_20130404_691_1-691.xml ");
  7. std::string oldStr("awp/awp");
  8. std::string newStr ("awp/awg");
  9. size_t pos = 0;
  10. while((pos = str.find(oldStr, pos)) != std::string::npos)
  11. {
  12. str.replace(pos, oldStr.length(), newStr);
  13. pos += newStr.length();
  14. }
  15. cout<<str<<endl;
  16. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
/home/docs/awp/awg/3/5/1/awp_awp.ch_20110504_1351_1-1351.html /home/docs/awp/awg/6/9/1/awp_awp.ch_20130404_691_1-691.xml  /home/docs/awp/awg/6/9/1/awp_awp.ch_20130404_691_1-691.xml /home/docs/awp/awg/6/9/1/awp/awg.ch_20130404_691_1-691.xml