【发布时间】:2022-06-10 21:13:47
【问题描述】:
有没有办法在定义向量的大小后初始化向量的前几个元素,例如 -
vector<int> vec (10);
这不起作用并产生编译器错误 -
vector<int> vec(10) {1,2,3};
例如对于数组,我们可以做同样的事情 -
int arr[5] {1,2,3}; // This will initialize the first 3 elements of the array to 1,2,3 and the remaining two to 0.
【问题讨论】: