我想声明多维(INT他的情况下二维)数组。我无法声明全局数组的大小。与一个维,一切正常:C++多维指针无需声明
#include <iostream>
#include <fstream>
using namespace std;
int N, M;
bool *table;
int main()
{
ifstream in ("in.txt");
in >> N >> M;
table = new bool[N];
return 0;
}
但是,如果我想声明二维数组,我得到一个错误: “M”不能出现在一个常数表达式
#include <iostream>
#include <fstream>
using namespace std;
int N, M;
bool **table;
int main()
{
ifstream in ("in.txt");
in >> N >> M;
table = new bool[N][M];
return 0;
}
我的选择除了声明数字而不是N和M,创建矢量数组或在主函数中声明表?
你为什么不使用'std :: vector'而不是担心这个? – Barmar