该程序假设需要一个size
数量的成对数字,这些数字是2D布尔数组中的坐标。触发的每个坐标都将值切换为TRUE
。出于某种原因,我在最后一行以及最后一行的最后一个空格中都有错误。有任何想法吗?布尔二维数组初始化错误C++
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
const int size = 10;
int *x = new int [size];
int *y = new int [size];
bool table[size][size] = {{false}};
for(int i = 1 ; i <= size; i++){
cin >> x[i] >> y[i];
if(x[i] <= size && y[i] <= size){
table[x[i]][y[i]] = true;
} else{
cout << "invalid input \n";
i--;
}
}
for(int a = 1; a <= size; a++){
for(int b= 1; b <= size; b++){
cout << table[a][b] << " ";
}
cout << "\n";
}
return 0;
}
为什么你从1迭代?应该从C中的0开始。 – yattering
数组从0开始... –
是的,我明白,但我不能使用0 ...它们是终止键。所以我只与从1开始的数组工作,而不是使它'我