به صورت زیر عمل کنید.
string str ="my name is window"; str.erase( remove(str.begin(),str.end(),' '),str.end());