Print statement without spaces.

Hello, i am trying to write a program to print a statement without spaces in it.
For example, if the statement is "Hello, i am Solidsnake", then it should print it as "Hello,iamsolidsnake". Can someone help me?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <iostream>
#include <algorithm>

std::string stripit_stripitrealgood(std::string s)
{
    s.erase( std::remove_if(s.begin(), s.end(), [](char ch) { return ch == ' ';}), s.end() ) ;
    return std::move(s) ;
}

int main()
{
    std::string str ;

    std::cout << "Input: " ;
    std::getline(std::cin, str) ;

    std::cout << stripit_stripitrealgood(str) << '\n' ;
}
Last edited on
I found the answer:
#include <iostream>
using namespace std;

int main()
{

string word;
getline(cin,word);
cout<<"You have entered :"<<word<<endl;
for(int i =0;i<word.length();i++)
{
if(word[i]==' ')
{
continue;
}
cout<<word[i];
}
}
Very good. Make sure to use indenting (and around here, [code] tags too).

@cire I think it unlikely that OPs professor expects OP to use the STL like that. Prof would like OP to figure out how to iterate over array and examine elements and take action (or inaction) as appropriate.
@Duoas:
Thanks for the tips. Will follow them in the future. Closing the thread.
Topic archived. No new replies allowed.