C ++ vector <char> and sockets
std::vector<char> b(100); send(z,&b[0],b.size(),0); Edit: I'm second to Ben Haymers and me22 . Also see this answer for a general implementation that is not trying to access the first element in empty vectors.
To expand on what sbi said, std :: vector is guaranteed to have the same memory format as the C-style array. Thus, you can use & myVector [0], the address of the 0th element, as the address of the beginning of the array, and you can safely use the elements myVector.size () of this array. Remember that they are both invalidated as soon as you then modify the vector!
One thing to consider: & v [0] is technically not allowed if the vector is empty, and some implementations will claim for you, so if you get buffers from others, make sure they are not empty using this trick.
C ++ 0x vector has a .data () member function (e.g. std :: string) to avoid this problem and make everything more understandable.