-
August 19th, 2014, 12:57 PM
#1
how to convert vector<vector<unsigned char> > to vector<unsigned char*> ?
Hello,
I have a vector<vector<unsigned char> > and I want to convert it to a vector<unsigned char*>. Can anyone provide sample code of how this is done?
Thanks!
Charles
Last edited by clow; August 19th, 2014 at 01:20 PM.
-
August 19th, 2014, 01:46 PM
#2
Re: how to convert vector<vector<unsigned char> > to vector<unsigned char*> ?
Victor Nijegorodov
-
August 20th, 2014, 08:32 AM
#3
Re: how to convert vector<vector<unsigned char> > to vector<unsigned char*> ?
Originally Posted by clow
Hello,
I have a vector<vector<unsigned char> > and I want to convert it to a vector<unsigned char*>. Can anyone provide sample code of how this is done?
Thanks!
Charles
The big question here is not how you convert from one container type to another, but rather, how will you be converting the elements themselves, eg: vector<unsigned char> to unsigned char*.
There are two issues:
1. vector<unsigned char> has length information. unsigned char* does not. How will you deal with this. Are we to just assume that your unsigned char sequences are null terminated? Or that someone else knows how long those sequences are?
2. vector<unsigned char> has ownership of its elements. unsigned char* does not. Who will be responsible for storing the elements, and for cleaning them up?
In any case, as VictorN replied, extracting an unsigned char* from vector<unisgned char> is done via the function "data". From there, a simple for loop can convert all elements.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|