Re: Copying Few Octets from Vector
On Apr 10, 3:18 pm, smilesonisa...@gmail.com wrote:
I am facing difficulty in copying few octets from a vector to a
buffer.
typedef unsigned char uint8_t;
I have a vector std::vector<uint8_t*> m_Data;
I'm not sure about the rest, but this vector doesn't contain
octets; it contains pointers.
which contains the following octets.
And none follow. So we have a vector which contains
pointers, and there are no octets. So far, so good.
I want to copy (30 74 64 230 0 8) to a buffer.
Where do these octets come from?
I saw in the web and got code where iterator is used to
copy all the octets not partial elements. How will I
retrieve 6 octets from the vector?
If the vector contains pointers, you can't. All you can get
from it is pointers.
Supposing you have a vector of octets:
std::vector< uint8_t > data ;
*and* supposing that offset plus length are less than the
size, you can copy the first length octets, starting from
offset, using std::copy:
std::copy( data.begin() + offset,
data.begin() + offest + length,
destination ) ;
You'd best check that offset + length <= data.size()
beforehand, though.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34