#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
Code Example |
---|
Cpp :: union of two arrays leetcode |
Cpp :: how to convert ascii to char in cpp |
Cpp :: to lowercase c++ |
Cpp :: print vector c++ |
Cpp :: detect cycle in an undirected graph |
Cpp :: function in struct c++ |
Cpp :: what is - in c++ |
Cpp :: array to string c++ |
Cpp :: unordered_set to vector |
Cpp :: how to empty string c++ |
Cpp :: how to find something in a string in c++ |
Cpp :: find element in vector |
Cpp :: print pattern and space in cpp |
Cpp :: Disabling console exit button c++ |
Cpp :: function overloading in c++ |
Cpp :: how to cout in c++ |
Cpp :: inserting element in vector in C++ |
Cpp :: cpp ifdef |
Cpp :: c++ write to csv file append |
Cpp :: how to use a non const function from a const function |
Cpp :: inheritance in c++ |
Cpp :: break statement in c++ program |
Cpp :: C++ sum a vector of digits |
Cpp :: sfml keyboard events cpp |
Cpp :: C++ wchar_t |
Cpp :: print fps sfml |
Cpp :: set iterator |
Cpp :: age in days in c++ |
Cpp :: c++ string find last number |
Cpp :: c++ write to file in directory |