views:

84

answers:

1

I have BYTE pointer. For example the length of this BYTE array is 10. How can I read 4 bytes from 3 position BYTE array?

Now I doing it so

BYTE *source = "1234567890\0";
BYTE* tmp = new BYTE[4+1]();
for(int i=0; i<4; i++)
{
tmp[i] = source[i+3];
}
+5  A: 

1)

 std::vector<BYTE> tmp1(source + 3, source + 7);

2)

BYTE tmp[5];
std::copy(source + 3, source + 7, tmp);

3)

BYTE tmp2[5];
memcpy(tmp, source + 3, 4 * sizeof(source[0]));
Alexey Malistov
Voted this up for the std::copy. Why do I never remember that exists?
John Burton