1#include <algorithm>
2
3int main()
4{
5 std::string str = "H e l l o";
6 str.erase(remove(str.begin(), str.end(), ' '), str.end());
7 std::cout << str; // Output Hello
8
9 return 0;
10}
1static std::string removeSpaces(std::string str)
2{
3 str.erase(remove(str.begin(), str.end(), ' '), str.end());
4 return str;
5}
1string removeSpaces(string str)
2{
3 stringstream s(str);
4 string temp;
5 str = "";
6 while (getline(s, temp, ' ')) {
7 str = str + temp;
8 }
9 return str;
10}
11//Input: Ha Noi Viet Nam
12//Output: HaNoiVietNam