简体   繁体   English

如何在 C++ 中将 CString 转换为 WCHAR* 并将 std::string 转换为 WCHAR*,而不是 wchar_t*

[英]How can I convert CString to WCHAR* and std::string to WCHAR* in C++, not wchar_t*

I want to convert CString to WCHAR* or std::string to WCHAR* in Visual Studio C++ MFC Application.我想在 Visual Studio C++ MFC 应用程序中将CString转换为WCHAR*或将std::string转换为WCHAR* I found in stackoverflow that it only has the solution for convert to wchar_t* .我在 stackoverflow 中发现它只有转换为wchar_t*的解决方案。

Please help me.请帮我。 Thank you!谢谢!

When you use CString, you could access the CW2A ATL macro,which converts CString to string.当您使用 CString 时,您可以访问 CW2A ATL 宏,它将 CString 转换为字符串。

CString theCStr;
std::string STDStr( CW2A( theCStr.GetString(), CP_UTF8 ) );

Or refer to this document .或者参考这个文件

I believe CString class can do such conversion:我相信CString class 可以做这样的转换:

CStringA a = "ANSI";
CStringW w(a);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM