CString 可以直接转换成 const char* 如果不需要更改数据而只是读取的话,可以直接用。要更改则可以拷贝出来或者你保证没有其他引用的情况下直接使用 char* p = const_cast<char*>(LPCSTR(str)) ——— CString str_receive="jkasiokkwesdjfjksdf"; char * pchr; pchr=str_receive.GetBuffer(str_receive.GetL...
CString m_Send="000A115033AA"; char/*wchar_t*/ *stops, s[3]; unsigned char uc; for (size_t i = 0; i < 10; i++) { s[0] = m_Send.GetAt(i * 2); s[1] = m_Send.GetAt(i * 2 + 1); s[2] = 0x0; uc = (unsigned char)strtoul/*wcstoul*/(s, &stops, 16); ...
CString *pPhoneNum =new CString((char*)buf, cs1.GetLength()); //将byte数组转换成cstring CString cs2 = *pPhoneNum;
下面是一个示例代码,展示如何将CString转换为const unsigned char数组: #include <afx.h> // 包含 MFC 头文件 #include <iostream> int main() { CString str = _T("Hello, World!"); // 假设你有一个 CString 对象 const unsigned char* pData = (const unsigned char*)str.GetString(); // 将 ...
可以这样:unsigned char str[10];CString mString = _T("1234");int len = mString.GetLength();strcpy(str, mString.GetBuffer(len));
):(a-'a'+10))int main(){ CString s="16ac8e54"; unsigned char&...
CString类型转换为char*类型 方法1.Char p[8];CString str=“hello”;memcpy(p, str, str.GetLength());方法2:char *p1;p1 = str.GetBuffer(str.GetLength());方法3:char *p1;p1 = (LPSTR)(LPCTSTR) str;
(a-'0'):(a-'a'+10))int main(){ CString s="16ac8e54"; unsigned char t[100]; int k=0; for(int i=0;i<s.GetLength()-1;i+=2) { t[k++]=hex2val(s[i])*16+hex2val(s[i+1]); } for(i=0;i<k;i++) printf("0x%x ",t[i]); return 0;} ...
因为你这个应该是需要十六进制数(而不是字符),所以只能这样:unsinged char b[6];b[0] = (unsigned char)atoi(a.Left(2).GetBuffer(0));CString a1 = a.Right(a.GetLength()-2);b[1] = atoi(a1.Left(2).GetBuffer(0));以下略,可以做城循环。错啦,忘了16进制。。。int char2...
unsigned char * data;CString str = "asdsad";data = (unsigned char*)str.GetBuffer(0);