我正在寻找的操作类型如下,但当然这段代码不起作用。
int a[3] = {0,1,2};
int b[3] = (a[2] = 0);
这样数组 b 有元素 {0,1,0}
和 a 有 {0,1,2}
最佳答案
Does there exist a data structure in cpp that easily provides a way to build a new one, based on an instance that already exists?
几乎所有标准容器都是可复制的。您可以使用 std::array
实现您的示例:
std::array a{0,1,2};
std::array b = a;
b[2] = 0;
关于c++ - cpp 中是否存在一种数据结构可以轻松地提供一种基于已存在的实例构建新数据结构的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56572022/