Doubt regarding the user of cin to read white space characters

For eg: if the code is :

cin>>ch;

while(ch != ‘.’)

{

     cout<<ch;

     cin>>ch;

}

And I give the input at console as " This is input"

What happens when input buffer sends white space to the program through cin ? Also if cin doesn’t send it to the program at all, does it simply discard that input ?

Also in case of an array, if we do:

int arr[50];

cin>>arr;

cout<<arr;

and try to give white space as input, the string is trimmed and nothing after the white space is read, why is that?:

INPUT: “This is Input”

OUTPUT: “This”

cin treats space as delimiter.
so anything after space will be ignored (i.e cin will not read it).

if u want to read complete line then use getline function

cin>>ch;
while(ch != ‘.’)
{
cout<<ch;
cin>>ch;
}

In this code, if my input is “Hello World!.” , the output will me “HelloWorld!”
If space is acting as a delimiter, why is it reading the input after space ?

becuase of while loop .
it is keep of on reading again n again.

u have given hello world. as input.
so first cin will read only hello (because just after it u have space )

and then because we r in a loop .
cin will read again and this time ur last string word
and thats why u r getting such output

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.