c++ 里面的字符类型转换

char* 转换成 LPCTSTR

char ch[1024] = "xxxx";
int num = MultiByteToWideChar(0,0,ch,-1,NULL,0);
wchar_t *wide = new wchar_t[num];
MultiByteToWideChar(0,0,ch,-1,wide,num);

LPCTSTR 转换成 char *

wchar_t widestr[1024] = L"xxxx";
int num = WideCharToMultiByte(CP_OEMCP,NULL,widestr,-1,NULL,0,NULL,FALSE);
char *pchar = new char[num];
WideCharToMultiByte (CP_OEMCP,NULL,widestr,-1,pchar,num,NULL,FALSE);

 

如果是一个路径里面有//,有的时候需要替换为\

#include <afxpriv.h>
CString subfile1 = subfile.Left(subfile.ReverseFind('.'));
subfile1.Replace('\\','/');
USES_CONVERSION;
m_db->UpDataPicDir((char*)T2A(subfile1), backid);

 char* 转CString

char* pData = "1234";
CString strData(pData);

 

关于字符串处理的文章

https://blog.csdn.net/GoForwardToStep/article/details/53079967

 

宽字符的拼接

 TCHAR buf[255];
wsprintf(buf, _T("RegisterUploadMinFile  %s ok! \n"), A2T(strFileName.c_str()));

 

 

CString强转int

mORDERINFO.back_id= _ttoi(CString((*p)["back_id"].asString().c_str()));

 

posted @ 2018-06-12 18:02  balder_m  阅读(301)  评论(0编辑  收藏  举报