Remove spaces from a given string | CPP program to Remove spaces from a given string ; Function to remove all spaces from a given string ; Driver program to test above function
#include <iostream> NEW_LINE #include <algorithm> NEW_LINE using namespace std ; string removeSpaces ( string str ) { str . erase ( remove ( str . begin ( ) , str . end ( ) , ' ▁ ' ) , str . end ( ) ) ; return str ; } int main ( ) { string str = " g ▁ eeks ▁ for ▁ ge ▁ eeks ▁ " ; str = removeSpaces ( str ) ; cout << str ; return 0 ; }