CString转LPCSTR,求帮助!解决方案
CString转LPCSTR,求帮助!#include atlconv.hCStringstrPathstrPath.Format(TEXT(%s\\%s),m_strPath,
CString转LPCSTR,求帮助!
#include <atlconv.h>
CStringstrPath;
strPath.Format(TEXT("%s\\%s"),m_strPath, *iter);
USES_CONVERSION;
Bitmap img( A2W(strPath) );
错误:无法从“CString”转“LPCSTR”
[解决办法]
C/C++ codeBitmap img( A2W(strPath.GetBuffer(0)) );
[解决办法]
[解决办法]
http://blog.csdn.net/pizi0475/archive/2010/03/04/5346708.aspx
[解决办法]
你是不是在工程里边预定义了_UNICODE了
[解决办法]
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);