Why would enter one character at a time when, according to input the correct but not in infinite loop ", strives for the c + + bosses
CodePudding user response:
# include & lt; Iostream>
Int main ()
{
Int a=1;
STD: : cin & gt; & gt; a;//runtime to 1 and a
STD: : cout & lt; & lt; "A=" & lt; & lt; A. & lt; & lt; STD: : endl;
STD: : cout & lt; & lt; "Cost flag:" & lt; & lt; STD: : cin. Fail () & lt; & lt; STD: : endl;
}
After the cin read failure, what is the value that you can't expect a,
Just at this time is zero, so the if statement,
The solution:
Put cin in the if, such as
if (cin & gt; & gt; A)
{
//what to do if succeed
}
The else
{
//what to do if fail
}
CodePudding user response: