这听起来可能很疯狂,但我想知道是否有可能让一个程序使用 C/C++。例如,对这个伪代码进行采样:
input int _n_
run loop for _n_ times such that:
declare _array1[]_
declare _array2[]_
.
.
declare _array'n'[]_
所以这里的问题有两个:
- 声明可变长度数组
- 声明一个可变数量(即 n 个)这样的数组。
最佳答案
真值表:
task / language | C | C++
-------------------------------+-----------------------+------------------------
Declare variable length arrays | Use VLAs | not possible without
| int arr[n]; | non-standard extensions
| | but use std::vector<T>
-------------------------------+---------------------+--------------------------
Declare a variable number | not possible but | not possible but use
(i.e. n number of) such arrays | use int arr[n][k]; | vector<vector<T>>
关于c++ - 如何使程序声明可变数量的不确定大小的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19210773/