memcpy如下所示使用它是否更好,或者std::copy()在性能方面更好用?为什么?
char *bits = NULL;
...
bits = new (std::nothrow) char[((int *) copyMe->bits)[0]];
if (bits == NULL)
{
cout << "ERROR Not enough memory.\n";
exit(1);
}
memcpy (bits, copyMe->bits, ((int *) copyMe->bits)[0]);
Run Code Online (Sandbox Code Playgroud) 我有这个代码:
std::array<int,16> copyarray(int input[16])
{
std::array<int, 16> result;
std::copy(std::begin(input), std::end(input), std::begin(result));
return result;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译此代码时,我收到此错误:
'std::begin': no matching overloaded function found
Run Code Online (Sandbox Code Playgroud)
和类似的错误std::end.
有什么问题以及如何解决?
我有一个语言内置数组,我需要将它的元素复制到容器库数组中进行一些处理。我尝试了几件事,但似乎不起作用。有没有办法将一种类型转换为另一种类型?
语言内置数组声明为:
int arr[] = {1,12,343,54,99};
Run Code Online (Sandbox Code Playgroud)
虽然库容器数组被声明为:
std::array<int,4> myarray = {4, 26, 80, 14} ;
Run Code Online (Sandbox Code Playgroud)
std::array 在 header 下声明<array>。