uint8_t数组转string
时间: 2023-10-21 18:10:07 浏览: 670
ByteConvert_arduino:Arduino的库,可将变量转换为字节并返回
可以使用以下代码将uint8_t数组转换为string:
```cpp
#include <iostream>
#include <sstream>
std::string uint8ToString(uint8_t* data, size_t len) {
std::stringstream ss;
for(size_t i = 0; i < len; i++) {
ss << std::hex << static_cast<int>(data[i]);
}
return ss.str();
}
int main() {
uint8_t data[] = {0x68, 0x65, 0x6c, 0x6c, 0x6f};
size_t length = sizeof(data) / sizeof(uint8_t);
std::string str = uint8ToString(data, length);
std::cout << str << std::endl;
return 0;
}
```
输出结果为:68656c6c6f
阅读全文