如何将大量整数作为数组中的输入,我希望数组接受超过 1k 个整数,但似乎无法这样做?

  • 本文关键字:数组 整数 1k 这样做 我希望 arrays testcase
  • 更新时间 :
  • 英文 :


感谢您查看我的问题,所以我想要一个 c++ 整数数组来存储大量元素,就像在我的一个测试用例中一样,我需要它存储大约 950 个整数和数组大小之前给出,但不知何故它不想将这么多数量的整数作为输入并存储它们。

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int ull;
int main()
{
int n;
cin>>n;
ull a[n];
for (ull i = 0; i < n; i++)
{
cin>>a[i];
}
for (auto x : a)
{
cout<<x<<" ";
}
return 0;
}

我希望它最多存储给定数量的整数,例如 1000,但事实并非如此。

您可以尝试使用 malloc 为数组动态分配内存。如果我没记错的话,你不能静态指定它,因为在编译时整数 n 是未知的。

最新更新