首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

CString转LPCSTR,求帮助!解决方案

2012-03-12 
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++ code
Bitmap img( A2W(strPath.GetBuffer(0)) );
[解决办法]

探讨

C/C++ code
Bitmap 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);

热点排行