c++ - 内河码头 : How to use TBase64Encoding's EncodeBytesToString method

标签 c++ encoding c++builder firemonkey c++builder-xe8

我正在尝试使用 TBase64Encoding 类的 EncodeBytesToString 方法将字节数组转换为 Base64 编码的字符串。 documentation对于 EncodeBytesToString 状态:

"Returns a string with the input array of bytes encoded up to the specified number of bytes."

因此,我尝试像这样对字节数组进行编码:

TFile * File = new TFile();

TBytes Bytes = File->ReadAllBytes("D:\\Sample.pdf");

TBase64Encoding * Encoder = new TBase64Encoding();

String EncodedBytes = Encoder->EncodeBytesToString(Bytes, Bytes.Length);

但是,我收到以下错误:

E2285 找不到“TNetEncoding::EncodeBytesToString(TByteDynArray,int)”的匹配项

我很困惑,因为文档似乎说我应该将一个 TBytes 对象和一个 int 传递到这个函数中。我在这里缺少什么?

最佳答案

试试这个:

//------------------------------------------------------------------------------
String __fastcall BytesToBase64( TByteDynArray _ArrayIn )
{
    TBase64Encoding * Encoding = new TBase64Encoding( 64, '\n' );
    String Result = Encoding->EncodeBytesToString( &_ArrayIn[0], _ArrayIn.High );
    delete Encoding;
    return Result;
}
//------------------------------------------------------------------------------
TByteDynArray __fastcall Base64ToBytes( String _64String )
{
    TByteDynArray My64Bytes = _64String.BytesOf();
    return TNetEncoding::Base64->Decode(&My64Bytes[0], My64Bytes.High);
}
//------------------------------------------------------------------------------

关于c++ - 内河码头 : How to use TBase64Encoding's EncodeBytesToString method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36500603/

相关文章:

c++ - 转换 - 错误 E2015,AnsiString(char) 和 AnsiString(short) 之间存在歧义

c++ - 构建时错误的预处理器指令

C++ 拆分宽字符字符串

Git:如何在命令行上指定包含八进制符号的文件名

Python:将字母数字字符串可逆地编码为整数

delphi - 如何使用 RTTI 访问 Delphi 数组属性

c# - 我正在尝试将我的旧 c++ 代码 "translate"转换为 c# 代码

c++ - 适配器模式 : Why would we need to subclass the Adaptee?

python - 如何在 Pandas 数据框中显示汉字?

c++ - 如何调试无痕崩溃