How to get the address of the std::vector buffer start most elegantly?

It’s really odd that nobody know this!!!
in C++11 you could use:

buffer.data()

it could get the address of the vector
I have test it:

vector<char>buffer;
buffer.push_back('w');
buffer.push_back('h');
buffer.push_back('a');
buffer.push_back('t');
buffer.push_back('\0');
char buf2[10];
memcpy(buf2,buffer.data(),10);

Specification here.

Leave a Comment