Populate a struct from data in a std::vector<unsigned char>
<p>I have the following struct defining data returned from a collection of HID device reports:</p>

<pre><code>struct DevInfo {
    char unknown[0x40];
    string name;
    char unknown2[0x240];
};
</code></pre>

<p>It's currently incomplete, but that's irrelevant to my question.  Previously, I was populating an instance of this struct using <code>memcpy</code> to copy data from a char array, like so:</p>

<pre><code>// get data from HID device
unsigned char *response = sendCommand(DEV_REPORT);

// Copy to struct
DevInfo *info;
memcpy(&amp;info, &amp;response[0], sizeof(response));

// Output name
cout &lt;&lt; "Name: " &lt;&lt; info-&gt;name &lt;&lt; "\n";
</code></pre>

<p>This worked, except that I was apparently doing something that I shouldn't (returning a reference to a char array from a function).  So, after researching, I switched to a safer <code>std::vector&lt;unsigned char&gt;</code> approach, but now I can't use <code>memcpy</code> to populate the data in the struct.</p>

<p>Someone advised me to use <code>std::vector&lt;DevInfo&gt;</code> instead of <code>std::vector&lt;unsigned char&gt;</code>, but the problem with that is there are several different reports that can be retrieved from the HID device, so I need to be able to populate different structs using the same function (<code>sendCommand</code>). </p>

<p>What's an appropriate way to get the binary data from my <code>std::vector&lt;unsigned char&gt;</code> to my <code>DevInfo</code> struct? </p>
