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/