如何在我的 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模板网!
如何在 Visual Studio 2008 中为我的应用程序设置图标How do I set the icon for my application in visual studio 2008?(如何在 Visual Studio 2008 中为我的应用程序设置图标?)
默认情况下,在 Visual Studio 中从项目中删除安全Remove secure warnings (_CRT_SECURE_NO_WARNINGS) from projects by default in Visual Studio(默认情况下,在 Visual Studio 中从项目中删除安全
如何在 Visual Studio 2008 中启动新的 CUDA 项目?How do I start a new CUDA project in Visual Studio 2008?(如何在 Visual Studio 2008 中启动新的 CUDA 项目?)
从 DLL 导出包含 `std::` 对象(向量、映射等)的类Exporting classes containing `std::` objects (vector, map etc.) from a DLL(从 DLL 导出包含 `std::` 对象(向量、映射等)的类)
发布版本与调试版本的运行方式不同的一些原因What are some reasons a Release build would run differently than a Debug build(发布版本与调试版本的运行方式不同的一些原因是什么
如何使用 Visual Studio 2005 设置 Google C++ 测试框架How to set up Google C++ Testing Framework (gtest) with Visual Studio 2005(如何使用 Visual Studio 2005 设置 Google C++ 测试框架 (gtest))