c++类中的二维数组出现莫名其妙的结果
c4droid吧
全部回复
仅看楼主
level 7
ryhehuhhgh 楼主
本来是想将数组初始化为 中间是0,边界是1,然而结果不可描述,见图片
源码如下
#include <iostream>
using namespace std;
const int width = 14;
const int hight = 10;
class WindoW{
public:
WindoW();
private:
void print()
{
for (int i=0;i<hight+2;++i)
{
for (int j=0;j<width+2;++j)
cout<<map[i][j]<<" ";
cout<<endl;
}
}
int map[width+2][hight+2];
};
WindoW::WindoW()
{
for (int i=1;i<width+1;++i)
map[0][i]=map[hight+1][i]=1;
for (int i=0;i<hight+2;++i)
map[i][0]=map[i][width+1]=1;
for (int i=1;i<hight+1;++i)
for (int j=1;j<width+1;++j)
map[i][j]=0;
print();
}
int main()
{
WindoW win;
return 0;
2018年08月14日 07点08分 1
level 7
ryhehuhhgh 楼主
将WindoW()函数中的三个循环颠倒顺序还会出现不同的结果,都不是想要的[小乖]
2018年08月14日 07点08分 2
level 14
int map[hight + 2][width + 2];
2018年08月14日 13点08分 4
想给自己一拳[紧张]
2018年08月14日 14点08分
1