+ 1

Program to omit whitespace in a given input?

challenge👍

16th Jan 2018, 7:23 AM
Littlerascal
Littlerascal - avatar
4 ответов
+ 2
Is this what you want? Input : Hello World ! Output : HelloWorld! C++ : #include<iostream> #include<string> #include<cctype> #include<algorithm> using namespace std; int main() { auto fx = [](char c){return isspace(c);}; string s; getline(cin,s); s.erase(remove_if(s.begin(),s.end(), fx),s.end()); cout<<s<<endl; } // Edit - Yes, there was the error that the remove function did not know what isspace is to be applied. So I defined a new lambda for the same. Now the code will work as expected.
16th Jan 2018, 7:59 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
Quick example in Python: x = input(“Enter two words”) x.replace(“ “, “”) # Replaces every space with an empty string in whatever you typed into input So “Hello World” would be “HelloWorld” And x.strip() removes all white space
16th Jan 2018, 8:28 AM
Travis
Travis - avatar
+ 2
@RAJALAKSHMI What is the error? // PS - I have removed the error that existed.
16th Jan 2018, 8:31 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
0
but it has an error ....*kinshuk vasisht
16th Jan 2018, 8:08 AM
Littlerascal
Littlerascal - avatar