vc++ - How to convert a CString into LPCWSTR(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)
.
另一种方法是使用专门的 CStringA
和 CStringW
类.这些是 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:vc++ - 如何将 CString 转换为 LPCWSTR


基础教程推荐
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01