将std::string转换为uint8 *类型
converting std::string to a uint8 *
我有一个函数,期望uint8 *表示缓冲区和int表示缓冲区长度。我该如何去转换std::string为uint8 *表示字符串?我尝试过使用c_str()将其转换为char *,但我仍然无法转换为uint8 *。
函数签名是这样的。
InputBuffer(const UINT8* buf, int len, bool usesVarLengthStreams = true)
,我正在尝试做以下
string ns = "new value";
int len = 10;
UINT8 * cbuff = ns; //(UINT8 *) ns.c_str(); doesn't work
in = new InputBuffer(cbuff, len);
string.c_str()返回一个(const char *)指针,而UINT8是:
typedef unsigned char UINT8;
所以代码应该是:
const UINT8 * cbuff = static_cast<const UINT8 *>(ns.c_str());
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- uint32, int16, uint8 .为什么这些常用的数据类型没有进入标准
- Opencv C++ 声明一个类型为 uint8 的矩阵
- Uint8 - 缺少类型说明符
- 将uint8 vector类型的元素转换为stringstream类型
- 将std::string转换为uint8 *类型