vc++ - 如何将 CString 转换为 LPCWSTR [英] vc++ - How to convert a CString into LPCWSTR

查看:18
本文介绍了vc++ - 如何将 CString 转换为 LPCWSTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图这样做,但我没有找到任何方法.我问这个是因为我是 Windows 新手.我尝试了 stl-strings,但 Visual Studio 2008- 在 stl-wstring-handling 中积累了错误.稍后我会在其他问题上说很多关于这件事的内容.现在有人可以阐明这个问题吗?

I tried to do this , but I didn't find any method for this. I am asking this due to the fact that I am new to windows. I tried stl-strings, but visual studio 2008- accumulates bugs in stl-wstring-handling. I will say a lot about that thing later, in other question. Now Can anybody shed light on this issue?

推荐答案

最简单的方法是使用 MFC 字符串转换宏,定义在:

The easiest way is to use the MFC String Conversion Macros, defined at:

https:///docs.microsoft.com/en-us/cpp/atl/reference/string-conversion-macros?view=msvc-160

例如,将CString转换为LPCWSTR的宏是CT2W(s).

For example, the macro to convert CString to LPCWSTR is CT2W(s).

另一种方法是使用专门的 CStringACStringW 类.这些是 CString 的相应 ascii 和宽版本,具体取决于您是否使用 UNICODE 标志进行编译.所以你可以使用:

Another way is to use the specialized CStringA and CStringW classes. These are the corresponding ascii and wide versions of CString depending on if you're compile with the UNICODE flag. So you can use:

CString your_string = "blah"
CStringW wide_string = your_string;

获取宽版本的字符串.

这篇关于vc++ - 如何将 CString 转换为 LPCWSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆