Re: Copying Few Octets from Vector
On Apr 10, 7:40 pm, smilesonisa...@gmail.com wrote:
On Apr 10, 10:10 pm, "Alf P. Steinbach" <al...@start.no> wrote:
* smilesonisa...@gmail.com:
I am facing difficulty in copying few octets from a
vector to a buffer.
typedef unsigned char uint8_t;
BTW: you shouldn't write this typedef yourself. You should
get it from <stdint.h>.
I have a vector std::vector<uint8_t*> m_Data;
which contains the following octets. I want to copy
(30 74 64 230 0 8) to a buffer. 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? I am new to C++ and facing lot of
problems in conversion. I tried a lot but couldnot
succeed.Could anybody help me in this regard?
Please explain your data structure.
You have a vector of pointers.
You just explained it for him:-).
Is it the first pointer in the vector that points to the
data listed above?
First pointer of vector points to first element of the
vector.
That's not possible, since the first pointer in the vector
has type uint8_t*, which is, of course, the same type as the
elements in the vector. And to point to an element of this
type, you'd need a uint8_t**.
How do you know the data size?
m_Data.size()
That's the number of pointers in the vector.
Also, please explain exactly what you're trying to
accomplish.
Basically Iam trying to get the first 6 octets of the
ethernet packet (destination mac address) from the
packet(decimal format) and try to compare with the a
different mac address. if they are same I need to do some
more operation. All the octets are stored in a vector.
You're still not very clear. First, do you have octets, or
decimal format? And what is the data structure which holds
them? If all of the octets are stored in a vector, then you
have octets, and not decimal format (which is text). And
that vector has the type std::vector< uint8_t >. And
getting the first six is trivial, using begin() and begin()
+ 6. (Provided, of course, that there are 6 or more octets
in the vector.)
--
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