这对我的同事来说是有用的,但对我来说不是吗

  • 本文关键字:对我来说 c++ arrays
  • 更新时间 :
  • 英文 :


#include <iostream>
using namespace std;
int main()
{
int i, x, j, t;
int size = rand() % 100;//random number
int a[size];// random number is the size of array

//array filling

for (i = 0; i <= size; i++) {
a[i] = rand() % 100;//new random number -> gets assigned as part of the array
}
for (x = 0; x < size; x++) {
for (j = x + 1; j < size; j++)
{
if (a[j] < a[x]) { //if x > x+1 sortieren
t = a[x];
a[x] = a[j];
a[j] = t;
}
}
}
for (x = 0; x < size; x++) {
cout << a[x] << "t";
}
return 0;
}

数组声明对我不起作用,但对我的同事起作用。IDE似乎坚持数组必须是一个常量。

根据C++标准,可变长度数组无效。有些编译器接受它作为非标准扩展。我建议您在需要动态数组时避免使用VLA,而是使用std::vector

相关内容

最新更新