Reputation: 13978
I have declared a vector like this
vector<char> vbuffer;
and used it as a receive buffer like this..
recv = read(m_fd, &m_vbuffer[totalRecv], SIZE_OF_BUFFER);
It seems like working and now I want to get the raw char data for parsing..
If I have defined a function like this..
char* getData(){
//return char data from the vector
}
How would I fill inside of the function? Thanks in advance..
Upvotes: 0
Views: 2044
Reputation: 308101
As long as you don't resize the vector in any way, you can use &vbuffer[0]
as a pointer to the array. There are many operations that will invalidate pointers to a vector though, make sure you don't call any of them while you have a pointer in use.
Upvotes: 3
Reputation: 249093
This will give you a pointer to the first element in the vector, so you can use it like an array:
&m_vbuffer[0]
Upvotes: 1