开发者

What header should I include for memcpy and realloc?

开发者 https://www.devze.com 2022-12-20 17:03 出处:网络
I am porting a project to the iPhone and it uses realloc and memcpy which are not found. What is the header to include?开发者_如何学编程

I am porting a project to the iPhone and it uses realloc and memcpy which are not found. What is the header to include?开发者_如何学编程

It's a project mixing Objective C and C++ and I am starting to be lost.

Thanks in advance for your help!


In 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.


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>.

There's not a direct C++ equivalent to realloc, though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号