gpt4 book ai didi

c++ - 在 C++ 中使用用户输入变量声明数组大小。在不同的 IDE 中有不同的结果?

转载 作者:行者123 更新时间:2023-11-30 01:09:02 24 4
gpt4 key购买 nike

<分区>

我需要创建一个程序,用户在其中输入所需的数组大小,然后 C++ 代码创建它并随后允许向其中输入数据。

这在 Code Blocks IDE 中有效,但在 Visual Studio Community 2015 中无效

当我将以下代码放入 CodeBlocks Version 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(即版本 14.0.25425)中输入相同的代码,则会出现错误:

expression must have a constant value

知道为什么会这样吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com