gpt4 book ai didi

c++ - 在 C++ 中的动态二维数组中填充 0 的更简洁方法

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:21:08 27 4
gpt4 key购买 nike

int **C = new int*[rows];
for(int i = 0; i < rows; i++){
C[i] = new int[cols];
for(int j = 0; j < cols; j++){
C[i][j] = 0;
}
}

我正在创建动态二维数组,但我们能否以某种方式在所有条目中用 0 初始化数组而不使用内部循环?

最佳答案

如果您使用 std::vector相反,它只是

std::vector<std::vector<int>> C(rows, std::vector<int>(cols));

关于c++ - 在 C++ 中的动态二维数组中填充 0 的更简洁方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48725421/

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