c++ char hex7 转字符串
您可以使用 std::string 类型来将 char 数组转换为字符串。以下是一个示例代码:
#include <iostream>
#include <string>
#include <sstream>
int main() {
char hex[7] = {'1', '2', '3', '4', '5', '6', '\0'}; // 假设 hex 数组表示十六进制数 "123456"
std::stringstream ss;
for (int i = 0; i < 6; i++) {
ss << hex[i];
}
std::string str = ss.str();
std::cout << str << std::endl; // 输出 "123456"
return 0;
}
在上面的代码中,我们使用 std::stringstream 类型将 char 数组中的每个字符逐个写入到一个字符串流中,然后使用 ss.str() 将字符串流转换为字符串。最终输出的字符串为 "123456"
原文地址: https://www.cveoy.top/t/topic/eXMG 著作权归作者所有。请勿转载和采集!