I have a buffer like this:
vector buf
How can I cast it to char*?
If I do:
(char *)buf
reinterpret_cast (&buf[0]);
The vector guarantees that its elements occupy contiguous memory. So the "data" you seek is actually the address of the first element (beware of vector
, this trick will fail with it). Also, why isn't your buffer vector
so that you don't need to reinterpret_cast?
reinterpret_cast(buf.data());