wchar_t的指针 [英] wchar_t pointer

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

问题描述

什么是错的:

wchar_t * t = new wchar_t;

t = "Tony";

我想我可以用一个指针的wchar_t作为一个字符串...

I thought I could use a wchar_t pointer as a string...

推荐答案

您code有两个问题。

Your code has two issues.

首先,托尼<​​/ code>是一个指向字符的字符串。 L托尼<​​/ code>是适当的宽字符串。

First, "Tony" is a pointer to a string of char's. L"Tony" is the appropriate wide string.

二,你分配一个 wchar_t的通过新的,然后立即重新分配指针托尼失去它的轨道。这将导致内存泄漏。

Second, you allocate a single wchar_t via new, then immediately lose track of it by reassigning the pointer to Tony. This results in a memory leak.

这篇关于wchar_t的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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