Answers for "c++ remove space from string"

C++
3

c++ remove whitespace from string

#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;
}
Posted by: Guest on November-10-2020
0

c++ remove space from string

static std::string removeSpaces(std::string str)
{
	str.erase(remove(str.begin(), str.end(), ' '), str.end());
	return str;
}
Posted by: Guest on March-02-2020

Code answers related to "c++ remove space from string"

Browse Popular Code Answers by Language