C++ 数据网址作为字符串到常量字节 *
C++ Data-Url as String to const byte *
我有一个文件的数据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 字符串中编码的内容,您可能希望使用不同的方法来解码
相关文章:
- 从不同线程使用int64的不同字节安全吗
- #定义c-预处理器常量..我做错了什么
- 用C++中的一个变量定义一个常量
- 什么时候在C++中返回常量引用是个好主意
- 代理对象的常量正确性
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 通过多个头文件使用常量变量
- 在UNIX系统中使用DIR查找文件的字节大小
- 在cuda线程之间共享大量常量数据
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 是默认情况下分配给char数组常量的值
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 常量"C"占用的空间(以字节为单位)
- 如何编写完全可移植的 4 字节字符常量的编译时初始化
- C++ 数据网址作为字符串到常量字节 *
- 传递指向常量指针的指针到字节数组的语义冲突
- GCC 错误,同时对常量无符号长字节使用代码块
- 从"常量字符*"转换为"字节"