Is it valid, to use std::string to hold binary data, to avoid manual dynamic memory management
<p>Pay attention to <code>base64_decode</code> in <a href="http://www.adp-gmbh.ch/cpp/common/base64.html" rel="nofollow">http://www.adp-gmbh.ch/cpp/common/base64.html</a></p>

<pre><code>std::string base64_decode(std::string const&amp; encoded_string)
</code></pre>

<p>The function is suppose to return <code>byte array</code> to indicate binary data. However, the function is returning <code>std::string</code>. My guess is that, the author is trying to avoid from perform explicit dynamic memory allocation.</p>

<p>I try to verify the output is correct.</p>

<pre><code>int main()
{
    unsigned char data[3];
    data[0] = 0; data[1] = 1; data[2] = 2;
    std::string encoded_string = base64_encode(data, 3);
    // AAEC
    std::cout &lt;&lt; encoded_string &lt;&lt; std::endl;


    std::string decoded_string = base64_decode(encoded_string);
    for (int i = 0; i &lt; decoded_string.length(); i++) {
        // 0, 1, 2
        std::cout &lt;&lt; (int)decoded_string.data()[i] &lt;&lt; ", ";
    }
    std::cout &lt;&lt; std::endl;
    getchar();
}
</code></pre>

<p><strong>The decoded output is correct. Just want to confirm, is it valid to <code>std::string</code> to hold binary data, to avoid manual dynamic memory management.</strong></p>

<pre><code>std::string s;
s += (char)0;
// s.length() will return 1.
</code></pre>
