I've read here on StackOveflow and other sources that the behavior of the remove function is simply re-ordering the original container so that the elements that are TO BE REMOVED are moved to the end of the container and ARE NOT deleted. They remain part of the container and the remove() function simply returns an iterator that delimits the end of the range of elements to keep.
So if you never actually trim off the portion of the container that has the values that have been 'removed', they should still be present.
But when I run the code below there are no trailing spaces after the alphanumeric characters that were not 'removed'.
int main()
{
std::string test "this is a test string with a bunch of spaces to remove";
remove(test.begin(), test.end(), ' ');
std::cout << test << std::endl;
return 0;
}
What is going on here? Seeing as I never call test.erase() shouldn't I have a bunch of trailing spaces on my string? Is it guaranteed that the 'removed' items will still be present after calling remove()?
PS-I'm not looking for suggestions on how to best remove spaces from a string, the above is simply an illustrative example of the remove() behavior that is confusing me.