CString strAAA;
int len=MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,strAAA,-1,NULL,0);
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,strAAA,-1,Buf,len);
第三个参数报错:
不能从 'const char * ' 转化为 'class CString '
CString 怎样转化为 const char * ,我是_unicode
int len=MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,strAAA,-1,NULL,0);
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,strAAA,-1,Buf,len);
第三个参数报错:
不能从 'const char * ' 转化为 'class CString '
CString 怎样转化为 const char * ,我是_unicode
解决方案 »
- 如何根据INPUT中的ID值获取此文本框?
- 求高手帮我讲一下运算符的重载
- 问一个关于如何修改文档标题的问题
- 文件和程序关联的问题
- 在2000,xp下如何獲得cpu的利用率?
- 我们使用别人的控件,在调用控件的redrawwindow后要在控件窗口上画些我们自己的东西,但由于我们无法判断控件重画已经完成,因此往往我们
- ?如何把CPropertySheet放到一个FormView上?
- 三个菜问题!!!!!!???????????UP有分!!!!!!!!!!
- 我急需一个图像配准的程序,希望大家能帮忙
- 请问有谁搞过计算机影像的技术?就是摄像信号直接在程序里处理?
- 学习编程顺序
- 如何设置子对话框的背景颜色呢??
LPWSTR lpszW = new WCHAR[255];LPTSTR lpStr = str.GetBuffer( str.GetLength() );
int nLen = MultiByteToWideChar(CP_ACP, 0,lpStr, -1, NULL, NULL);
MultiByteToWideChar(CP_ACP, 0, lpStr, -1, lpszW, nLen);
AFunctionUsesWCHAR( lpszW );
delete[] lpszW;
1、GetBuffer函数:
使用CString::GetBuffer函数。
char *p;
CString str="hello";
p=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();将CString转换成char * 时
CString str("aaaaaaa");
strcpy(str.GetBuffer(10),"aa");
str.ReleaseBuffer();
当我们需要字符数组时调用GetBuffer(int n),其中n为我们需要的字符数组的长度.使用完成后一定要马上调用ReleaseBuffer();
还有很重要的一点就是,在能使用const char *的地方,就不要使用char *2、memcpy:
CString mCS=_T("cxl");
char mch[20];
memcpy(mch,mCS,20);3、用LPCTSTR强制转换: 尽量不使用
char *ch;
CString str;
ch=(LPSTR)(LPCTSTR)str;CString str = "good";
char *tmp;
sprintf(tmp,"%s",(LPTSTR)(LPCTSTR)str);4、
CString Msg;
Msg=Msg+"abc";
LPTSTR lpsz;
lpsz = new TCHAR[Msg.GetLength()+1];
_tcscpy(lpsz, Msg);
char * psz;
strcpy(psz,lpsz);
CString类向const char *转换
char a[100];
CString str("aaaaaa");
strncpy(a,(LPCTSTR)str,sizeof(a));
或者如下:
strncpy(a,str,sizeof(a));
以上两种用法都是正确地. 因为strncpy的第二个参数类型为const char *.所以编译器会自动将CString类转换成const char *.CString转LPCTSTR (const char *)
CString cStr;
const char *lpctStr=(LPCTSTR)cStr;LPCTSTR转CString
LPCTSTR lpctStr;
CString cStr=lpctStr;将char*类型的变量赋给CString型的变量
可以直接赋值,如:
CString myString = "This is a test";
也可以利用构造函数,如:
CString s1("Tom");将CString类型的变量赋给char []类型(字符串)的变量
1、sprintf()函数
CString str = "good";
char tmp[200] ;
sprintf(tmp, "%s",(LPCSTR)str);
(LPCSTR)str这种强制转换相当于(LPTSTR)(LPCTSTR)str
CString类的变量需要转换为(char*)的时,使用(LPTSTR)(LPCTSTR)str然而,LPCTSTR是const char *,也就是说,得到的字符串是不可写的!将其强制转换成LPTSTR去掉const,是极为危险的!
一不留神就会完蛋!要得到char *,应该用GetBuffer()或GetBufferSetLength(),用完后再调用ReleaseBuffer()。2、strcpy()函数
CString str;
char c[256];
strcpy(c, str);char mychar[1024];
CString source="Hello";
strcpy((char*)&mychar,(LPCTSTR)source);
CString 用法不对MultiByteToWideChar 最方便的使用方法是用 _bstr_t
我的的是_UNICODE,UNICODE