+ 1
Program to omit whitespace in a given input?
challengeš
4 Answers
+ 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.
+ 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
+ 2
@RAJALAKSHMI
What is the error?
// PS - I have removed the error that existed.
0
but it has an error ....*kinshuk vasisht