在MFC编程中,经常会遇到各种字符类型之间的转换问题,现将应用过程遇到情况总结如下:
1、char*转CString
char szPath[50];
CString str;
str.Format("%s",szPath);
2、WCHAR*转int
WCHAR Speck_num[5];
int Max_Speckle_num = _wtoi(Speckle_num);
m_Frame =Max_Speckle_num;
3、string转CString
CString.format("%s",string.c_str());
4、CSring转string
string s(CString.GetBuffer());
CString str = "sdfg";
string s = (LPCTSTR)str;
5、string转char*
char* p =string.c_str();
6、char转int
char *a="13";
int b =atoi(a);
7、WCHAR*转int
WCHAR a[5];
int b = _wtoi(a)