cstring to char*,const char*

http://yanghao.blog.51cto.com/357234/71226

http://student.csdn.net/space.php?uid=3913&do=blog&id=9158

http://yangyzqo.spaces.live.com/Blog/cns!EC9D7DF132A21AB4!375.entry

 

Q1:eVC中CString转Char*

#include <atlconv.h>


 CString str = _T("CString");
 char *pBuffer = NULL;
 pBuffer = new char[str.GetLength()+1];
 ZeroMemory(pBuffer, str.GetLength()+1);

USES_CONVERSION;
pBuffer=(char*)W2A((LPCTSTR)str);

..................

 delete[] pBuffer;

 

Q2:Char* 转CString

CString *str = new CString[MAX_SIZE];

char * des= new char[j-i]; //分配空间;
strncpy(des,&sResult[i],j-i);
str= des;

你可能感兴趣的:(cstring to char*,const char*)