CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2013
    Posts
    32

    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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: how to convert vector<vector<unsigned char> > to vector<unsigned char*> ?

    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: how to convert vector<vector<unsigned char> > to vector<unsigned char*> ?

    Quote Originally Posted by clow View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured