CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Mar 2009
    Posts
    166

    how best to combine multiple vector<unsigned char> to std::string?

    Hello all,

    two questions:

    1. I have some vector<unsigned char> containing binary data. I would like to combine them into one std::string. How is the correct way to accomplish this?

    This is my best guess for sample code:
    Code:
    vector<unsigned char> data; //conatins some data
    vector<unsigned char> data2; //contains more data
    string temp(data.begin(), data.end());
    temp.append(data2.begin(), data2.end());
    will this code work with binary data, or will it null terminate?


    2. A similiar problem.. I have some unsigned char* variables, and I want to combine them into one std::string. How can I accomplish this?

    will the member append() work here? or will it null terminate?

    something like:
    Code:
    unsigned char* data; //conatins some data
    unsigned char* data2; //contains more data
    string temp(reinterpret_cast<const char*>(data));
    temp.append(string(reinterpret_cast<const char*>(data2)));
    will the above sample code work without null termination?

    Regards,
    Ellay K.
    Last edited by ekhule; March 16th, 2012 at 09:58 AM.

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