[英]c++ library for copying array contents to the pointer
int a[4]={1,2,3,4};
int* b = new int[4];
Is there any library function like std::copy to copy the elements from an array a at to pointer b in c++ ? 是否有类似std :: copy的库函数将数组a中的元素复制到c ++中的指针b?
Yes there is, it's called std::vector<>
; 是的,它叫做
std::vector<>
; you would use it in your code as follows: 您将在代码中使用它,如下所示:
std::vector<int> a { 1, 2, 3, 4 };
auto b = a;
Is there any library function like std::copy to copy the elements from an array a at to pointer b in c++ ?
是否有类似std :: copy的库函数将数组a中的元素复制到c ++中的指针b?
Yes, that's std::copy
: 是的,那是
std::copy
:
std::copy( std::begin( a ), std::end( a ), b );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.