回 帖 发 新 帖 刷新版面

主题:轉換CString

請問如何轉換CString為LPCSTR?
環境為VC++ 2005.

回复列表 (共2个回复)

沙发

MSDN有例子.我用的是Vs.net 2003
 CString   theString(  "This   is   a   test"   );   
 LPTSTR   lpsz   = new  TCHAR[theString.GetLength()+1];   
 _tcscpy(lpsz,   theString);

板凳

实在不行你用个简单的。效果一样!
  CString   theString(   "This   is   a   test"   );   
  LPTSTR   lpsz   =   new   char[theString.GetLength()+1];   
  sprintf(lpsz,"%s",(LPCTSTR)theString);

我来回复

您尚未登录,请登录后再回复。点此登录或注册