memcpy with startIndex?

后端 未结 9 1253
星月不相逢
星月不相逢 2020-12-24 11:31

I wish to copy content of specific length from one buffer to another from a specific starting point. I checked memcpy() but it takes only the length of content

9条回答
  •  抹茶落季
    2020-12-24 11:55

    If you're using c++, it is probably better to use std::copy() instead of memcpy(). std::copy can take pointers just as easily as iterators.

    e.g.

    int src[20];
    int dst[15];
    
    // Copy last 10 elements of src[] to first 10 elements of dst[]
    std::copy( src+10, src+20, dst );
    

    As with memcpy(), it's your responsibility to make sure the pointers are valid.

    NOTE. If your usage is performance critical you may find a memcpy() as detailed in the other answers quicker, but probably not by much.

提交回复
热议问题