C++ 为什么在不提供整数输入时会进入无限循环? #包括 使用名称空间std; 内部主(空) { int n; 标签0: coutn; if(cin.fail()) { trycin.ignore()afterclear的coutp可能的重复现在工作得很好。应该将
为什么在不提供整数输入时会进入无限循环?C++ 为什么在不提供整数输入时会进入无限循环? #包括 使用名称空间std; 内部主(空) { int n; 标签0: coutn; if(cin.fail()) { trycin.ignore()afterclear的coutp可能的重复现在工作得很好。应该将,c++,C++,为什么在不提供整数输入时会进入无限循环? #包括 使用名称空间std; 内部主(空) { int n; 标签0: coutn; if(cin.fail()) { trycin.ignore()afterclear的coutp可能的重复现在工作得很好。应该将goto转换为正确的循环。 #include <iostream> using namespace std; int main (void) { int n; label0: cout<<"Ple
#包括
使用名称空间std;
内部主(空)
{
int n;
标签0:
coutn;
if(cin.fail())
{
trycin.ignore()
afterclear
的coutp可能的重复现在工作得很好。应该将goto
转换为正确的循环。
#include <iostream>
using namespace std;
int main (void)
{
int n;
label0:
cout<<"Please an integer value\n";
cin>>n;
if ( cin.fail() )
{
cout<<"Please enter proper value\n";
cin.clear();
goto label0;
}
else
{
cout<<"You entered"<<n<<"\n";
}
return 0;
}