我需要創建一個程序,用戶可以在其中輸入所需的數組大小,然後C++代碼創建它並隨後允許數據輸入。用C++中的用戶輸入變量聲明數組大小。不同的IDE有不同的結果?
這個作品在代碼塊IDE而不是在Visual Studio社區2015年
當我把下面的代碼在代碼塊版13.12它的工作原理
#include<iostream>
using namespace std;
int main()
{
int count;
cout << "Making the Array" << endl;
cout << "How many elements in the array " << endl;
cin >> count;
int flex_array[count];
for (int i = 0; i < count; i = i + 1)
{
cout << "Enter the " << i << " term " << endl;
cin >> flex_array[i];
}
for (int j = 0; j < count; j = j + 1)
{
cout << "The " << j << " th term has the value " << flex_array[j] << endl;
}
return 0;
}
但是,如果我進入相同的代碼Visual Studio 2015(ie版本14.0.25425),我得到錯誤:
expression must have a constant value
任何想法爲什麼會發生這種情況?
你並不需要表現出同樣的代碼片斷兩次。 –