fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int RemoveWordFromLine(string line, string word)
  6. {
  7. // ==========================
  8. string tmp_str="",spacebar=" ";
  9. int start=0,end=-1;
  10. for(int i=0;i<line.length();i++)
  11. {
  12.  
  13. if(isspace(line[i])||int(line[i])==44||int(line[i])==46)
  14. {
  15. cout<<tmp_str<<" "<<start<<" "<<end<<endl; // compare
  16. if(tmp_str==word)
  17. {
  18. line.erase(start,end);
  19. }
  20. tmp_str="";
  21. start=i+1;
  22. end=i;
  23.  
  24. } else
  25. {
  26. tmp_str+=line[i];
  27. end++;
  28.  
  29. }
  30.  
  31. }
  32. if(tmp_str==word)
  33. {
  34. line.erase(start,end);
  35. }
  36. cout<<tmp_str<<" "<<start<<" "<<end<<endl; // compare
  37. cout<<line<<endl;
  38.  
  39.  
  40. // ==========================
  41. }
  42.  
  43. int main() {
  44. string line="The house whirled around two or three-times and roses lowly through the air. Dorothy felt as if she.";
  45. string word="the";
  46. RemoveWordFromLine(line,word);
  47.  
  48. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
The 0 2
house 4 8
whirled 10 16
around 18 23
two 25 27
or 29 30
three-times 32 42
and 44 46
roses 48 52
lowly 54 58
through 60 66
the 68 70
 72 71
The house whirled around two or three-times and roses lowly through