【发布时间】:2018-06-23 14:05:46
【问题描述】:
我是 C++ 新手,但仍在尝试自己的方式。我试图调整我在 SO 上找到的一个函数,以便根据需要将我的字符串转换为字节:
void hexconvert(const char *text, unsigned char bytes[])
{
int i;
int temp;
for (i = 0; i < 4; ++i) {
sscanf(text + 2 * i, "%2x", &temp);
bytes[i] = temp;
}
cout << bytes;
}
hexconvert("SKY 000.001\n", );
我遇到的问题是:
1) 我不确定如何修改 for 循环来处理我的字符串。 2) 我不确定我应该使用什么作为函数中第二个参数的输入。
有人可以帮忙吗?
谢谢
【问题讨论】:
-
你为什么不直接做
std::cout << std::hex << whatever << std::endl;? -
您好,感谢您的回复。如果我需要访问我的变量而不是控制台打印,这将如何工作?