Saved Bookmarks
| 1. |
Read the following C++ statements: charstr[50];cin>>str;cout<<str;During execution, if the string given as input is “GREEN COMPUTING”, the output will be only the word “GREEN”. Give reason for this. What modification is required to get the original string as output? |
|
Answer» cin>>word; cout<<word; It displays “HAPPY” because cin takes characters upto the space. That is space is the delimiter for cin. The string after space is truncated. To resolve this use gets() function. Because gets() function reads character upto the enter key. Hence gets(word); puts(word); Displays “HAPPY NEW YEAR” |
|