Visual Studio在编译此c++代码时出现错误。它说大小应该是一个常量变量。我试过让它保持恒定,但它不起作用。
int size;
cout << "Please Enter the array size : " ;
cin >> size;
int myArr[size];
发布于 2018-09-30 06:40:40
数组的大小在编译时必须是已知的。在您的示例中,大小在运行时是已知的,因此您必须从堆中分配数组。
int size;
std::cin >> size;
int* myArr = new int[size];
// ...
delete[] myArr;
https://stackoverflow.com/questions/52573110
复制相似问题