gpt4 book ai didi

C++ 复制一个用 new 创建的数组

转载 作者:太空狗 更新时间:2023-10-29 21:44:48 25 4
gpt4 key购买 nike

我在 C++ 中使用 new 创建了两个数组 List1List2List1 用数据更新。我想将 List1 复制到 List2。我尝试使用

std::copy(std::begin(List1), std::end(List1), std::begin(List2));

但是,这不起作用并给出以下错误消息:

error: ‘begin’ is not a member of ‘std’

对于这个错误有什么可能的建议吗?或者在 C++ 中复制的替代方法?

最佳答案

“我用 C++ 中的 new 创建了两个数组 List1 和 List2

beginend 自由函数不适用于指针。

即使一切正确,您也可能以没有匹配调用 begin(T *&)

告终

T 是指针的类型。

使用 std::vectorstd::list 其他 STL 容器或只是简单的静态数组来处理 std::beginstd::end

关于C++ 复制一个用 new 创建的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19253498/

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