How do I combine multiple char reads into a std::vector?
<p>I'm reading multiple reports from a HID device into an <code>unsigned char</code>, then trying to copy the data to a <code>std::vector</code>.  I'm also writing the data out to a file for hex analysis, whose content appears to be correct when I view it.  However, the <code>std::vector</code> doesn't appear to contain the correct data when I dump it to the console.</p>

<p>This is the code:</p>

<pre><code>typedef vector&lt;unsigned char&gt; buffer_t;

buffer_t sendCommand (hid_device *devh, const unsigned char cmd[], int reports) {
    unsigned char outbuf[0x40];
    buffer_t retbuf(0x40 * reports);

    hid_write(devh, cmd, 0x41);

    int i;
    FILE *file = fopen("test.out", "w+b");
    while (i++ &lt; reports) {
       hid_read(devh, outbuf, 0x40);
       fwrite(outbuf, 1, sizeof(outbuf), file);
       retbuf.push_back(*outbuf);
    }
    fclose(file);
    cout &lt;&lt; &amp;retbuf[0];
    return retbuf;
}
</code></pre>

<p>I have a feeling I'm way off the mark here; I'm fairly new to C/C++, and I've been stuck with this for a while now.  Can anyone tell me what I'm doing wrong, or point me in a better direction?</p>
