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

Convert any File to Base64 (and back)

Demonstrates how to get the contents of any file as a base64 string, and then write it back.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkBinDataW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkBinDataW bd;

    //  This example will load a PDF and return it as a base64 string.
    success = bd.LoadFile(L"qa_data/pdf/helloWorld.pdf");
    if (success != true) {
        wprintf(L"Failed to load file.\n");
        return;
    }

    const wchar_t *b64Str = bd.getEncoded(L"base64");
    wprintf(L"%s\n",b64Str);

    //  Now write the base64 string back to the binary PDF file:
    CkBinDataW bd2;
    success = bd2.AppendEncoded(b64Str,L"base64");
    success = bd2.WriteFile(L"qa_output/helloWorld.pdf");
    }