减少LPWSTR中的字符并将其另存为LPCWSTR [英] reduce characters from LPWSTR and save it as LPCWSTR

查看:55
本文介绍了减少LPWSTR中的字符并将其另存为LPCWSTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我有一个另存为LPWSTR的字符串.
我必须对此字符串进行更改(减少一些字符)并将其另存为LPCWSTR.
我该怎么办?

谢谢

Hello,
I have a string saved as LPWSTR.
I have to make a change in this string (reduce some characters) and save it as LPCWSTR.
How can i do it?

Thanks

推荐答案

您不需要从非常量字符串到常量字符串的任何转换.显然,它们在所需的分配方向上兼容.让我们看看:

You don''t need any conversion from non-constant to constant string. Apparently, they are compatible in the assignment direction you want. Let''s see:

#include <windows.h>

//...

LPWSTR variable = L"my string";
variable[0] = 'M';
LPCWSTR constString = variable;



如果您需要执行相反操作,则需要强制类型转换,因为这将打破关于字符串数据不可更改的假设.有两种方法:



If you need to do the opposite, type cast is needed, because it would break the assumption on the string data being immutable. There are two ways:

LPWSTR newString = (LPWSTR)constString;
LPWSTR newString2 = const_cast<LPWSTR>(constString);



—SA



—SA


这篇关于减少LPWSTR中的字符并将其另存为LPCWSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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