将const Byte*转换为std::string

visual Convert const Byte* to std::string c++

本文关键字:std string 转换 const Byte      更新时间:2023-10-16

如何将const Byte*转换为std::string。我尝试了以下命令

std::string sTemp(reinterpret_cast<const char*>(ByteBuffer));

其中ByteBuffer为const Byte*。使用上述代码未获得sTemp中ByteBuffer的值请帮助

谢谢,

如果ByteBuffer包含以null结尾的字符串,那么代码应该可以正常工作。

如果没有,则需要提供其长度作为string构造函数的第二个参数。

以上假设Byte是我认为的,ByteBuffer不是NULL

c++中没有'Byte'这样的数据类型。我假设它是一个8位的数据存储,如果它存在的话,在这种情况下,您的代码是正确的。确保缓冲区中有一个空字符- ''。