+ 1
Program to omit whitespace in a given input?
challenge👍
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.
+ 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