本文介紹了將 CString 轉換為 const char*的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何在我的 Unicode MFC 應用程序中將 CString
轉換為 const char*
?
How do I convert from CString
to const char*
in my Unicode MFC application?
推薦答案
要將 TCHAR
CString 轉換為 ASCII,請使用 CT2A
宏 - 這也將允許您將字符串轉換為 UTF8(或任何其他 Windows 代碼頁):
To convert a TCHAR
CString to ASCII, use the CT2A
macro - this will also allow you to convert the string to UTF8 (or any other Windows code page):
// Convert using the local code page
CString str(_T("Hello, world!"));
CT2A ascii(str);
TRACE(_T("ASCII: %S
"), ascii.m_psz);
// Convert to UTF8
CString str(_T("Some Unicode goodness"));
CT2A ascii(str, CP_UTF8);
TRACE(_T("UTF8: %S
"), ascii.m_psz);
// Convert to Thai code page
CString str(_T("Some Thai text"));
CT2A ascii(str, 874);
TRACE(_T("Thai: %S
"), ascii.m_psz);
還有一個宏可以從 ASCII -> Unicode (CA2T
) 轉換,只要你有 VS2003 或更高版本,你就可以在 ATL/WTL 應用程序中使用這些.
There is also a macro to convert from ASCII -> Unicode (CA2T
) and you can use these in ATL/WTL apps as long as you have VS2003 or greater.
有關詳細信息,請參閱 MSDN.
See the MSDN for more info.
這篇關于將 CString 轉換為 const char*的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!