mthread said:
Hi,
I am copying data from one buffer(this data is a binary data not
string) to another buffer. Earlier when I used C, I used the memcpy
function call to copy the values. Is there any equivalent replacement
in C++ for this call.
Yes. std::memcpy(). It's a direct replacement.
Ok, yes, I know, that's not what you meant. But sometimes the best
tool in C++ to do a particular job is the tool inherited from C.
It really depends on what you're doing. What kind of data is it,
where did it come from, how is it formatted, where will it be
stored, and how is it used?
If the source is a raw stream of bytes, (say from a communications
line), or the source and destination are disparate data types and
can not be made the same type (for whatever reason), then just memcpy.
Brutal, dangerous, and requires that you know what you're doing, yes;
but beautifully simple and efficient.
Otherwise, if you can arrange for the source and destination to be
the same data type, you can just assign one to the other, either
using arrays and for-loops and pointers, or (preferably) using
std containers and iterators and algorithms.