我在C++初学者的数组,并试图通过for循环将数据插入到一个数组,但是,它抛出Stack around the variable 'numArray' was corrupted.
C++插入通过for循环
我的代码:
//Initializing and declairing variables
int numVal = 0;
int numArray[] = {0};
cout << "Enter the number of values to average: ";
cin >> numVal;
//Loop through to accept all values and allocate them to an array
for (int i = 0; i < numVal; i++) {
cout << "[" << i << "] = ";
cin >> numArray[i];
}
什么我的代码错了?
编辑:我必须使用数组而不是向量。
是否有任何理由你不使用'std :: vector'或类似的容器? –
你认为在初始化之后数组会有多少元素? – jpw
练习指示我使用数组而不使用矢量,初始化时我们不知道大小 – Shepard