+ 1
Pls correct my String program
Task: in place of an integer ranging (0-9) we should print "GG",rest as it is. Ex: I/P: 2 out of 5 are well O/p: GG out of GG are well string enter; cin>>enter; int j; for(int i=0;i<enter.length();i++) {j=enter[i]; if(j>=48&&j<=57) { cout<<"GG"; } else cout<<enter[i]; }j=0; return 0;
1 Respuesta
+ 2
by default cin reads one word at a time. to read whole line at once you can use getline() .
int main(){
string enter;
getline(cin,enter); // to read entire line
int j;
for(int i=0;i<(int)enter.length();i++)
{j=enter[i];
if(j>=48&&j<=57)
{
cout<<"GG";
}
else
cout<<enter[i];
}j=0;
return 0;
}
There are some other ways too..