Consider this following program:
#include <iostream>
#include <string>
#include <algorithm> // std::remove
int main ()
{
std::string str ("This is an example sentence blah");
std::remove(str.begin(), str.end(), '\t');
std::cout << str ;
return 0;
}
There is a tab between the words (is,an) and (an,example), others are spaces.
I expected the output to be :
This isanexample sentence blah
Instead, i am getting the following output:
This isanexample sentence blahah
Is there a buffer overrun somewhere for the extra 'ah'?
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?