c++ - how to copy char* to a vector<char> and retrieve it? -
i have char *recbuffer
, int *packetlength
point info , size
int i=0; vector<char> temp;//copy buffer while(i<*packetlength) { temp.push_back(*(recbuffer+i)); i++; } ...do //retrieve recbuffer = temp ????
i believe easiest way populate vector using constructor:
vector<char> temp(recbuffer, recbuffer + *packetlength);
as retrieving back, utilize method data
:
recbuffer = temp.data();
note: data
available in c++11
in case not compile using new standard, utilize &temp[0]
proposed @juanchopanza.
c++ stl
No comments:
Post a Comment