Home > Back-end >  C o bosses
C o bosses

Time:09-15

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:

reference 1st floor alittlenewbiek 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
}

Ha ha ha, have a little idea, but I still don't quite understand, thank you

CodePudding user response:

You are using plastic, STD: : cin> & gt; Num here failed, so can't determine the value of num

CodePudding user response:

reference qq_40162781 reply: 3/f
you use plastic, STD: : cin> & gt; Num here failed, so can't determine the value of num

Got it, thank you

CodePudding user response:

You can add a judgment, to ensure that the input is digital,
"The c + + console program to determine input digital"
Wish I could help you!

CodePudding user response:

reference 5 floor MianHou reply:
can add a judgment, to ensure that the input is digital,
"The c + + console program to determine input digital"
Wish I could help you!

Thank you thanks??
  • Related