C++怎么将 CString 转换成 unsigned char 的数组?

怎么将CString类型的变量 s="16ac8e54" 转换成 unsigned char t[100] ={0x16,0xac,0x8e,0x54}

最好能给具体代码

鸿蒙传说
浏览 858回答 2
2回答

慕后森

123456789101112#include<stdio.h>#include&nbsp;<afx.h>#define&nbsp;hex2val(a)&nbsp;(('0'<=a&&a<='9')?(a-'0'):(a-'a'+10))int&nbsp;main(){&nbsp;CString&nbsp;s="16ac8e54";&nbsp;unsigned&nbsp;char&nbsp;t[100];&nbsp;int&nbsp;k=0;&nbsp;for(int&nbsp;i=0;i<s.GetLength()-1;i+=2)&nbsp;{&nbsp;&nbsp;t[k++]=hex2val(s[i])*16+hex2val(s[i+1]);&nbsp;}12&nbsp;&nbsp;&nbsp;&nbsp;for(i=0;i<k;i++)&nbsp;&nbsp;&nbsp;&nbsp;printf("0x%x&nbsp;",t[i]);12&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Cocos2d-x