C++ 金元';文件输入后,不能停止
我试图在直接从命令行输入文件后使用cin读取int。这是我的档案:C++ 金元';文件输入后,不能停止,c++,cin,C++,Cin,我试图在直接从命令行输入文件后使用cin读取int。这是我的档案: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 它们是81个数字。下面是有问题的代码: #include <iostream> using n
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
它们是81个数字。下面是有问题的代码:
#include <iostream>
using namespace std;
int main()
{
int array[81];
for(int i = 0; i < 81; i++)
cin >> array[i];
int x = 999;
cin >> x;
cout << x << endl;
return 0;
}
#包括
使用名称空间std;
int main()
{
int数组[81];
对于(int i=0;i<81;i++)
cin>>阵列[i];
int x=999;
cin>>x;
cout
不会停止并直接将999打印为输出。我尝试了cin.clear()
和cin.ignore(INT_MAX,'n')
但它们都不起作用。然后我想输入这样的文件有什么特别之处,所以我在运行a.out后键入了所有81个数字(不使用
输入),如果我这样做,程序将继续接受输入,而不会停止或打印
我不知道我遇到了什么
cin >> x;
失败,并且您的代码无法检测到它。请使用:
if ( cin >> x )
{
// Reading to x was successful. Use it.
cout << x << endl;
}
else
{
// Reading to x was not successful. Figure out what to do.
}
if(cin>>x)
{
//读x是成功的。使用它。
库特
失败,并且您的代码无法检测到它。请使用:
if ( cin >> x )
{
// Reading to x was successful. Use it.
cout << x << endl;
}
else
{
// Reading to x was not successful. Figure out what to do.
}
if(cin>>x)
{
//读x是成功的。使用它。
难道忽略的形式是std::cin.ignore(std::numeric\u limits::max(),'\n');
包括
。忽略的形式是std::cin.ignore(std::numeric\u limits::max(),'\n');
包括
。