how to remove all spaces in a string in C++ code example
Example 1: c++ remove space from string
static std::string removeSpaces(std::string str)
{
str.erase(remove(str.begin(), str.end(), ' '), str.end());
return str;
}
Example 2: remove space in string c++
string removeSpaces(string str)
{
stringstream s(str);
string temp;
str = "";
while (getline(s, temp, ' ')) {
str = str + temp;
}
return str;
}
//Input: Ha Noi Viet Nam
//Output: HaNoiVietNam