#include <algorithm>
int main()
{
std::string str = "H e l l o";
str.erase(remove(str.begin(), str.end(), ' '), str.end());
std::cout << str; // Output Hello
return 0;
}
static std::string removeSpaces(std::string str)
{
str.erase(remove(str.begin(), str.end(), ' '), str.end());
return str;
}
#include<iostream>
#include<algorithm>
using namespace std;
main() {
string my_str = "This is C++ Programming Language";
cout << "String with Spaces :" << my_str << endl;
remove(my_str.begin(), my_str.end(), ' ');
cout << "String without Spaces :" << my_str;
}
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