|
1
2
|
#include <stdio.h>
#include <tchar.h>
|
unsigned char [] 转为 CString
|
1
2
3
4
5
6
7
8
9
|
unsigned
char
temp[] = { 0x01, 0xC2, 0x24, 0x80, 0x32, 0x00, 0x00, 0x19, 0x00, 0x00 };
TCHAR
sz[2] = { 0 };
CString str;
for
(
int
i = 0; i <
sizeof
(temp) /
sizeof
(temp[0]); i++)
{
_stprintf(sz, TEXT(
"%02X"
), temp[i]);
str += sz;
}
cout << str << endl;
|
CString 转为 unsigned char []
|
1
2
3
4
5
6
7
8
9
10
11
|
CString str =
"01C22480320000190000"
;
unsigned
char
temp2[10];
TCHAR
sz2[3] = { 0 };
int
nLen = str.GetLength() / 2;
for
(
int
j = 0; j < nLen; j++)
{
sz2[0] = str[j * 2];
sz2[1] = str[j * 2 + 1];
_stscanf(sz2, TEXT(
"%2X"
), &temp2[j]);
}
|

本文介绍如何在C/C++中实现unsigned char数组与CString之间的相互转换。通过示例代码展示了如何将unsigned char数组转换为CString,反之亦然。这对于处理二进制数据或特定格式字符串的应用场景非常有用。

545

被折叠的 条评论
为什么被折叠?



