title: How to remove an entire word in a sentence c++
body: <p>I want to remove specific word in a sentences and I have tried to breakdown the sentences into word and compare the word but when i call the erase function , the index will update. I have tried another method while it will delete substring in a word which i dont want to. Can anyone help me out a bit? what approach i should use.  </p>
  
  <p><strong>input</strong> </p>
  
  <blockquote>
    <p>The house whirled around two or three times and rose slowly through the air.</p>
  </blockquote>
  
  <p><strong>output</strong></p>
  
  <blockquote>
    <p>The house whirled around two or three times and rose slowly through  air.</p>
  </blockquote>
  
  <p>here is my prototype of the function</p>
  
  <pre><code>int RemoveWordFromLine(string line, string word)
  {
    // ==========================
    string tmp_str="",spacebar=" ";
    int start=0,end=-1;
    for(int i=0;i&lt;line.length();i++)
    {
  
      if(isspace(line[i])||int(line[i])==44||int(line[i])==46)
      {
        cout&lt;&lt;tmp_str&lt;&lt;" "&lt;&lt;start&lt;&lt;" "&lt;&lt;end&lt;&lt;endl; // compare
        if(tmp_str==word)
        {
          line.erase(start,end);  
        }
        tmp_str="";
        start=i+1;
        end=i;
  
      } else
      {
        tmp_str+=line[i];
        end++;
  
      }
  
    }
      if(tmp_str==word)
        {
          line.erase(start,end);  
        }
      cout&lt;&lt;tmp_str&lt;&lt;" "&lt;&lt;start&lt;&lt;" "&lt;&lt;end&lt;&lt;endl; // compare
      cout&lt;&lt;line&lt;&lt;endl;
  
  
    // ==========================
  }
  </code></pre>
  
  <p><a href="https://ideone.com/oWzxTC" rel="nofollow noreferrer">ideone's link</a></p>