cstring 转 unsigned char[]
场景:把CString转unsigned char的方法,多谢
【求助】把CString转unsigned char的方法,谢谢
定义
unsigned char by[4];
转换
Cstring abc="123";
by[3]=(LPSTR)(LPCSTR)abc;
error C2440: '=' : cannot convert from 'char *' to 'unsigned char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
这样做就提示报错了,不能将by[3]为123,有什么办法呢?谢谢了
------解决方案--------------------
by[3] = atoi(abc.GetBuffer());
这样是不是你需要的呢?
------解决方案--------------------
你的GetBuffer不能带默认参数吗?那就用0就好了。
如果是16进制,可以考虑用
sscanf(abc.GetBuffer(0),"%x",&by[3]);
------解决方案--------------------
Cstring abc="123";
by[3]=_ttoi(abc);
------解决方案--------------------
memcpy(&by[3],abc,abc.GetLength());
【求助】把CString转unsigned char的方法,谢谢
定义
unsigned char by[4];
转换
Cstring abc="123";
by[3]=(LPSTR)(LPCSTR)abc;
error C2440: '=' : cannot convert from 'char *' to 'unsigned char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
这样做就提示报错了,不能将by[3]为123,有什么办法呢?谢谢了
------解决方案--------------------
by[3] = atoi(abc.GetBuffer());
这样是不是你需要的呢?
------解决方案--------------------
你的GetBuffer不能带默认参数吗?那就用0就好了。
如果是16进制,可以考虑用
sscanf(abc.GetBuffer(0),"%x",&by[3]);
------解决方案--------------------
Cstring abc="123";
by[3]=_ttoi(abc);
------解决方案--------------------
memcpy(&by[3],abc,abc.GetLength());