C++ 我应该为 memcpy 和 realloc 包含什么头文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2283712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What header should I include for memcpy and realloc?
提问by AP.
I am porting a project to the iPhone and it uses realloc
and memcpy
which are not found. What is the header to include?
我移植了一个项目,iPhone和它使用realloc
和memcpy
未找到。要包含的标题是什么?
It's a project mixing Objective C and C++ and I am starting to be lost.
这是一个混合了 Objective C 和 C++ 的项目,我开始迷失了。
Thanks in advance for your help!
在此先感谢您的帮助!
回答by GManNickG
In C:
在 C 中:
#include <string.h> // memcpy
#include <stdlib.h> //realloc
In C++, remove the .h
and prefix with a c
. In C++, they will be placed in the std
namespace, but are also global.
在 C++ 中,删除.h
和 前缀c
。在 C++ 中,它们将被放置在std
命名空间中,但也是全局的。
回答by Tyler McHenry
In C++ it's more idiomatic to use std::copy
than C's memcpy
, although the latter does work just as well. To get std::copy
, you need to #include <algorithm>
.
在 C++ 中,它std::copy
比 C更惯用memcpy
,尽管后者也能正常工作。要得到std::copy
,你需要#include <algorithm>
。
There's not a direct C++ equivalent to realloc
, though.
但是,没有直接的 C++ 等价于realloc
。