I have char *RecBuffer, int *packetLength point to the data and the size
int i=0;
vector<char> temp;//copy the buffer
while(i<*packetLength)
{
temp.push_back(*(RecBuffer+i));
i++;
}
...do something
//retrieve it now
RecBuffer = temp ????
I believe the easiest way to populate the vector is using the constructor:
vector<char> temp(RecBuffer, RecBuffer + *packetLength);
As for retrieving it back, use the method data:
RecBuffer = temp.data();
NOTE: data will only be available in C++11 in case you do not compile using the new standard, use &temp[0] as proposed by @juanchopanza.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With