C
Carl Forsman
given the following base64_encode function, I will read bytes from a
file and encode the binary data into a single line CString;
but something wrong with the following code with errors!
================
std::string base64_encode(unsigned char const* bytes_to_encode,
unsigned int in_len) {
================
#define BYTE unsigned char
....
int size;
BYTE* buffer;
....
std::ifstream inputFile("C:\\test.bin", std::ios::in |
std::ios::binary);
// open the binary file to read
if (inputFile.is_open())
{
inputFile.seekg(0, std::ios::end);
size = inputFile.tellg(); // size of the file
buffer = new BYTE[size];
inputFile.read(buffer, size);
// encode binary data into a Base64 string
std::string data = base64_encode(buffer, size);
// convert std::string to CString
CString st = CString(data);
}
file and encode the binary data into a single line CString;
but something wrong with the following code with errors!
================
std::string base64_encode(unsigned char const* bytes_to_encode,
unsigned int in_len) {
================
#define BYTE unsigned char
....
int size;
BYTE* buffer;
....
std::ifstream inputFile("C:\\test.bin", std::ios::in |
std::ios::binary);
// open the binary file to read
if (inputFile.is_open())
{
inputFile.seekg(0, std::ios::end);
size = inputFile.tellg(); // size of the file
buffer = new BYTE[size];
inputFile.read(buffer, size);
// encode binary data into a Base64 string
std::string data = base64_encode(buffer, size);
// convert std::string to CString
CString st = CString(data);
}