主题:一个关于数组初始化的问题
今日编的一个小程序:
#include <iostream.h>
#include <stdlib.h>
#define MaxSize 1024
struct SPNode
{
int row,col;
int value;
};
struct SPMatrix
{
int rowm,coln,vcount;
SPNode data[MaxSize];
};
int Row=3;
int Col=3;
int A[Row][Col];
void Input()
{
int i,j;
cout<<"稀疏矩阵的行数:"<<endl;
cin>>Row;
cout<<"稀疏矩阵的列数:"<<endl;
cin>>Col;
cout<<"请输入矩阵的元素:"<<endl;
for(i=0;i<Row;i++)
{
for(j=0;j<Col;j++)
cin>>A[i][j];
}
cout<<"你输入的矩阵为:"<<endl;
for(i=0;i<Row;i++)
for(j=0;j<Col;j++)
cout<<A[i][j]<<endl;
}
int main()
{
Input();
return 0;
}
编译后抱错:
Compiling...
1037.cpp
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2057: expected constant expression
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2466: cannot allocate an array of constant size 0
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2057: expected constant expression
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2466: cannot allocate an array of constant size 0
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2087: '<Unknown>' : missing subscript
执行 cl.exe 时出错.
1037.obj - 1 error(s), 0 warning(s)
请大家帮忙看一下,先谢谢了!!!!
#include <iostream.h>
#include <stdlib.h>
#define MaxSize 1024
struct SPNode
{
int row,col;
int value;
};
struct SPMatrix
{
int rowm,coln,vcount;
SPNode data[MaxSize];
};
int Row=3;
int Col=3;
int A[Row][Col];
void Input()
{
int i,j;
cout<<"稀疏矩阵的行数:"<<endl;
cin>>Row;
cout<<"稀疏矩阵的列数:"<<endl;
cin>>Col;
cout<<"请输入矩阵的元素:"<<endl;
for(i=0;i<Row;i++)
{
for(j=0;j<Col;j++)
cin>>A[i][j];
}
cout<<"你输入的矩阵为:"<<endl;
for(i=0;i<Row;i++)
for(j=0;j<Col;j++)
cout<<A[i][j]<<endl;
}
int main()
{
Input();
return 0;
}
编译后抱错:
Compiling...
1037.cpp
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2057: expected constant expression
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2466: cannot allocate an array of constant size 0
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2057: expected constant expression
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2466: cannot allocate an array of constant size 0
E:\C++6.0\MSDev98\MyProjects\4037\1037.cpp(16) : error C2087: '<Unknown>' : missing subscript
执行 cl.exe 时出错.
1037.obj - 1 error(s), 0 warning(s)
请大家帮忙看一下,先谢谢了!!!!