"TechNovice" <> wrote in message
news:CNmjb.91099$k74.71902@lakeread05...
> Thanks for your response, but I found that this works very well
> ****code****
> int input_number;
> if(cin>>input_number)
> cout<<"valid number"<<endl;
> else
> cout<<"invalid number"<<endl;
Yes, it does. This is because the expression 'cin>> input_number'
returns a reference to 'cin', so has the same testing effect
as 'if(cin)'. Indeed what you just showed me is the 'idomatic'
way to use the >> operator.
But now try it in a loop as in your original post.
(or simply try a subsequent 'cin' operation without
first doing the 'clear()' and 'ignore()')
-Mike