473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

C++ memcpy

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.
Apr 12 '07 #1
3 4341
barcaroller wrote:
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.
Apr 12 '07 #2
In article <ev**********@aioe.org>, barcaroller <ba*********@music.netwrote:
>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.hor <cstringand
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).
--
Greg Comeau / 4.3.9 with C++0xisms now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Apr 12 '07 #3
barcaroller wrote:
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.

Apr 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: franky.backeljauw | last post by:
Hello, following my question on "std::copy versus pointer copy versus member copy", I had some doubts on the function memcpy, as was used by tom_usenet in his reply. - Is this a c++ standard...
16
by: Delali Dzirasa | last post by:
I would have a number packed with its hex representation of the integer below is some sample code of what is being done. int value = 20; //in hex it is 0x14 AddData (value); .. .. ..
6
by: Samee Zahur | last post by:
Hi all, I'm a little confused - my guess is memcpy is no longer (or perhaps never was) a standard c++ function, since it has very little type check into it - and can potentially create havoc for...
5
by: manya | last post by:
Ok, it's been a while since I've done the whole memcpy stuff with C++ and I'm having a hard time remembering everything. I hope, however, that you can help me with my problem. I memcpy a...
35
by: Christopher Benson-Manica | last post by:
(if this is a FAQ or in K&R2, I didn't find it) What parameters (if any) may be 0 or NULL? IOW, which of the following statements are guaranteed to produce well-defined behavior? char src;...
16
by: Amarendra GODBOLE | last post by:
Hi, I am a bit confused over the correct usage of memcpy(). Kindly help me clear the confusion. The linux manpage for memcpy(3) gives me the following prototype of memcpy(3): #include...
33
by: Case | last post by:
#define SIZE 100 #define USE_MEMCPY int main(void) { char a; char b; int n; /* code 'filling' a */
6
by: myhotline | last post by:
hi all im very confused about using memcpy and i have three questions....memcpy takes a pointer to src and a pointer to dest and copies src to destination...but im very confuzed about when to...
18
by: Mark | last post by:
Hi List, I want to write a function to copy some data out of a hardware buffer. The hardware can change the contents of this buffer without it being written to by my function. I want to use...
18
by: sam | last post by:
(newbie)Technically what's the difference between memset() and memcpy() functions?
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.