我创建了一个这样的数组 R:
int * R = new int[n];
其中 n 取一个很大的值,比如 100,000。我想在 C++ 中将数组的所有整数初始化为 1。最好/最快的方法是什么?或者,遍历整个数组是唯一的选择吗?
最佳答案
"What is the best/fastest way to do this?"
在 C++ 中你使用 std::vector<int> R(n,1);
相反。
如果您需要 int*
在其他地方,你指的是R.data()
.
关于c++ - 如何在 C++ 中将动态创建的大整数数组初始化为特定整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28798737/