How to cast vector to char*

reinterpret_cast<char*> (&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 <bool>, this trick will fail with it). Also, why isn’t your buffer vector<char> so that you don’t need to reinterpret_cast?

Update for C++11

reinterpret_cast<char*>(buf.data());

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)