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


- C++ 协变模板 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 从python回调到c++的选项 2022-11-16
- Stroustrup 的 Simple_window.h 2022-01-01
- 静态初始化顺序失败 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01