The thing is I usually would use a for loop to handle this kind of thing but this method seems to be much more efficient. The documentation on cplusplus was a bit hard to comprehend for me.
std::string no_space(std::string x)
{
x.erase(std::remove(x.begin(), x.end(), ' '), x.end());
return x;
}