C++ Erase not working as expected : <p>Consider this following program:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;    // std::remove

int main ()
{
  std::string str ("This is   an   example sentence blah");
  std::remove(str.begin(), str.end(), '\t');
  std::cout &lt;&lt; str ;
  return 0;

}
</code></pre>

<p>There is a tab between the words (is,an) and (an,example), others are spaces.  </p>

<p>I expected the output to be :</p>

<blockquote>
  <p>This isanexample sentence blah</p>
</blockquote>

<p>Instead, i am getting the following output:</p>

<blockquote>
  <p>This isanexample sentence blahah</p>
</blockquote>

<p>Is there a buffer overrun somewhere for the extra '<strong>ah</strong>'?</p>

<p>More:
I noticed after several runs that, the number of trailing letters at the end is proportional to number of tabs being removed. In this case there are 2 tabs in the string, hence 2 extra trailing characters. I can take care of it by using erase, but why does it happen? I am not sure if it's a design flaw or am i missing something?</p>
