我无法初始化 WCHAR [英] I cannot initializate WCHAR

查看:39
本文介绍了我无法初始化 WCHAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作和WCHAR.但它不起作用,我总是收到一个错误:

I need to make and WCHAR. But it wont work, and i always get an error:

Error   C2440   'initializing': cannot convert from 'const wchar_t [11]' to 'WCHAR *'
 StateError (active)    E0144   a value of type "const wchar_t *" cannot be used to initialize an entity of type "WCHAR *

我的代码:

WCHAR *Testlooll = L"TEST";

推荐答案

L"TEST"const wchar_t[5] 类型的字符串文字,它是一个const 字符数组(因为文字存在于只读内存中).您正在尝试初始化一个 WCHAR*,它是一个指向 非常量 字符的指针,以指向该数组.

L"TEST" is a string literal of type const wchar_t[5], which is an array of const characters (since the literal exists in read-only memory). You are trying to initialize a WCHAR*, which is a pointer to a non-const character, to point at that array.

初始化一个指向非常量字符数据的指针以指向一组const字符数据是在 C++98 中已弃用(以保持与遗留代码的向后兼容性),并且在 C++11 中是非法的.

Initializing a pointer to non-const character data to point at an array of const character data is deprecated in C++98 (to maintain backwards compatibility with legacy code), and is illegal in C++11 onwards.

您需要根据以下内容更改Testlooll的声明:

You need to change the declaration of Testlooll according:

const WCHAR *Testlooll = L"TEST";

或者:

LPCWSTR Testlooll = L"TEST";

这篇关于我无法初始化 WCHAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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