How do I check that input is empty

How do I check that input is empty.
for input
*
5
2
after this ch will have value =’*’ until ‘x’ or ‘X’ is not passed to it and the loop will go on running infinite times. How to check if there is no input after 2.

Hello @Mohit_Maroo,

  1. In this question, the test case you have given is not valid.
    Because, it says that the loop will terminate only for ‘x’ or ‘X’

  2. If you wants to know how to iterate a loop till you get the input and terminate for no input.
    Code Segment:
    while(cin>>ch){
    cout<<ch<<" ";
    }
    Explanation:
    For no input, cin>>ch will return 0 i.e. false.
    Hence, terminating the loop.

Hope, this would help.
Give a like if you are satisfied.

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.