C++
C++
Base64 Encode a File
_LANGUAGE_ to Base64 encode the contents of a file.Chilkat C++ Downloads
#include <CkFileAccess.h>
void ChilkatSample(void)
{
bool success = false;
// Get the contents of a file into a base64 encoded string:
CkFileAccess fac;
const char *strBase64 = fac.readBinaryToEncoded("c:/data/something.pdf","base64");
if (fac.get_LastMethodSuccess() != true) {
std::cout << fac.lastErrorText() << "\r\n";
return;
}
// Now write the string to a file:
success = fac.WriteEntireTextFile("c:/data/something_pdf_base64.txt",strBase64,"us-ascii",false);
if (success != true) {
std::cout << fac.lastErrorText() << "\r\n";
return;
}
std::cout << "Success!" << "\r\n";
}