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
基础教程推荐
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
