Unicode字符集、多字节字符集下:CString->const char*、CString->LPCSTR

Unicode字符集、多字节字符集下:CString->const char*、CString->LPCSTR

1、CString->const char*
(1)多字节字符集下:CString->LPCTSTR可以自动转化!
(2)Unicode下:使用函数 “wsprintfA”

// BmpName->cstr_BmpName;
// CString BmpName;//变量BmpName
// const char* cstr_BmpName;////变量cstr_BmpName
// FILE * __cdecl fopen(_In_z_ const char * _Filename, _In_z_ const char * _Mode);
eg:	
	CString BmpName;//变量BmpName
	const char* cstr_BmpName;
	char temp[100];
	::wsprintfA(temp, "%ls", (LPCTSTR)BmpName);
	cstr_BmpName = temp;
	FILE *fpo = fopen(cstr_BmpName, "rb");

2、CString->LPCSTR
(1)多字节字符集下:CString->LPCTSTR可以自动转化!

// void SaveBmp(LPCSTR lpFileName);
// CString str;
eg:
	SaveBmp(str);

(2)Unicode下:使用 “USES_CONVERSION” 和 “T2A”

// str -> lpstr
// CString str;
// LPCSTR lpstr;
eg:
	str = str + L".bmp";	
	USES_CONVERSION;
	LPCSTR lpstr = (LPCSTR)T2A(str);
	SaveBmp(lpstr); 

3、CString = CString + CString

// CString str;
多字节字符集下:str = str + ".bmp";
Unicode下:str = str + L".bmp";

你可能感兴趣的:(类型转换)