C++ 数据网址作为字符串到常量字节 *

C++ Data-Url as String to const byte *

本文关键字:常量 字节 字符串 数据网 C++      更新时间:2023-10-16

我有一个文件的数据URL作为std:string。base64 编码的数据必须解码,然后传递给此函数:

open (const byte *  data, long size)

所以首先我提取编码的数据

size_t pos = dataurl.find_first_of(',');
std::string encoded = dataurl.substr(spos + 1);

然后我使用这个base64解码器

std::string decoded = base64_decode(encoded);

那么,如何将字符串类型的"解码"转换为字节*?以下代码产生错误

open((byte *)decoded.c_str(), decoded.size() + 1);
//>>error: 'byte' was not declared in this scope

/编辑:所以有一个类型定义

typedef uint8_t     byte

编码的数据是图像!

看起来您正在删除const . c_str()返回一个const char *。 你的演员阵容应该是(const byte *)的。

>字节是一个无符号字符open((unsigned char *)decoded.c_str(), decoded.size() + 1);

是的,根据原始 base64 字符串中编码的内容,您可能希望使用不同的方法来解码