C++ memcpy

B

barcaroller

Does C++ have an equivalent for C's memcpy? I have two memory blocks
(created using new, not malloc) and I need to copy the contents of one to
the other. The memory blocks are just that; they are not objects.
 
R

red floyd

barcaroller said:
Does C++ have an equivalent for C's memcpy? I have two memory blocks
(created using new, not malloc) and I need to copy the contents of one to
the other. The memory blocks are just that; they are not objects.

Yes, memcpy. The C Standard Library is part of the C++ Standard Library.
 
G

Greg Comeau

Does C++ have an equivalent for C's memcpy? I have two memory blocks
(created using new, not malloc) and I need to copy the contents of one to
the other. The memory blocks are just that; they are not objects.

memcpy is part of the C++ Standard Library as well.
If can be accessed via <string.h> or <cstring> and
may or may not need std:: qualification (the standard
is clear on when it's required, but compilers are
across the board on applying it still).
 
G

Gianni Mariani

barcaroller said:
Does C++ have an equivalent for C's memcpy? I have two memory blocks
(created using new, not malloc) and I need to copy the contents of one to
the other. The memory blocks are just that; they are not objects.

C++ has memcpy.

#include <cstring>

int main()
{
char a[10], b[10];

std::memcpy(a, b, sizeof(a));
}

You can also use std::copy. On some compilers, a std::copy of POD's
will turn into a memcpy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top