Sample code for 30+ languages & platforms
Unicode C++

Append Encoded Binary Data to StringBuilder

Demonstrates how to append encoded binary data to the contenets of a StringBuilder.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkBinDataW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkBinDataW bd;

    success = bd.LoadFile(L"qa_data/jpg/starfish.jpg");
    if (success == false) {
        wprintf(L"Failed to load file.\n");
        return;
    }

    //  For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
    CkStringBuilderW sb;
    sb.Append(L"{ \"jpg\": \"");
    //  GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
    bd.GetEncodedSb(L"base64",sb);
    sb.Append(L"\" }");

    wprintf(L"%s\n",sb.getAsString());

    //  Output looks like this:
    //   { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }
    }