how to remove unwanted space out of your answer?
i did a coding just like the one above but they are saying i have unwanted space in my output.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string line=" London is one of the most popular\t cities in the world.\n\n"
" It is\t\t home to charming pubs, world-class\t (and often free)\n\n"
" museums, tons of history.";
cout<<"Primary text:\n"<<line;
string result="";
for(int i=0;i<line.size();i++)
{
if(i==0)
{
while(line[i]==' '||line[i]=='\t'||line[i]=='\n')
i++;
}
if(line[i]=='\t')
{
while(line[i]=='\t')i++;
}
result+=line[i];
if(line[i]==' ')
{
while(line[i]==' ')i++;
i--;
}
if(line[i]=='\n')
{
while(line[i]=='\n')i++;
if(line[i]==' ')
{
while(line[i]==' ')i++;
i--;
}
}
}
cout<<"\nResulting text:\n"<<result;
}
Comments
Leave a comment