What’s wrong with this:
wchar_t * t = new wchar_t;
t = "Tony";
I thought I could use a wchar_t pointer as a string…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your code has two issues.
First,
"Tony"is a pointer to a string ofchar‘s.L"Tony"is the appropriate wide string.Second, you allocate a single
wchar_tvia new, then immediately lose track of it by reassigning the pointer to Tony. This results in a memory leak.