我想用一个用户自制的矩阵读取并使用二维数组打印出来,但它无法正常工作。它进入了一个无限循环。
#include <iostream>
using namespace std;
int main()
{
int numrow, input = 0;
while(cin)
{
cout << "Enter Row: " << endl;
cin >> input;
numrow++;
}
int b[numrow][numrow];
for (int i = 0; i < numrow; i++)
{
for(int j = 0; j < numrow; j++)
{
input >> b[i][j];
cout << b[i][j];
}
}
return 0;
}
答案 0 :(得分:0)
while(cin){
是问题,你的while循环中没有break
个问题。
您可以使用if
语句替换它。另请记住在使用变量之前初始化变量:int numrow = 0, input = 0;
b[i][j] = input; // you probably meant to do this