将const Byte*转换为std::string
visual Convert const Byte* to std::string c++
如何将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位的数据存储,如果它存在的话,在这种情况下,您的代码是正确的。确保缓冲区中有一个空字符- ' '。
相关文章:
- cppcheck在const std::string[]上引发警告
- 将std::string传递给WriteConsole API
- 为std::string的某个索引赋值
- 使用 std::string () const 函数启动线程或未来
- 当我们进行一些操作时,应该使用什么'std::string'或'std::stringstream'?
- 如何更改大小(std::string)
- std::string 的对象真的可以移动吗?
- SegFault 同时使用 std::string::operator+= 和函数作为参数
- 无法从 std::string 中提取C++ Unicode 符号
- std::string 构造函数如何处理固定大小的 char[]?
- 真的没有来自 std::string_view 的 std::string 的显式构造函数吗?
- 将C++ std::string 转换为 UTF-16-LE 编码的字符串
- 重载 + 自己的类和 std::string 的运算符
- 如何使用 std::string 作为 QHash 的键?
- 将日语 wstring 转换为 std::string
- 可以从std::string继承以提供类型一致性吗
- 构造函数采用std::string_view与std::string并移动
- 在共享缓冲区内存中创建 ::std::string 对象
- std::string.size() 未知行为
- Valgrind 在 std::string::swap 中报告 SIGILL