Solved

wcscpy question

Posted on 2002-04-25
3
598 Views
Last Modified: 2013-11-20
Hi, what is wrong here?

     wchar_t tag[30];
     wcscpy(tag, "haha");

error C2664: 'wcscpy' : cannot convert parameter 2 from 'char [5]' to 'const unsigned short *'

How to fix it? I need to use
wcsstr(line, tag) later on.


Thanks.
0
Comment
Question by:hoooi
  • 2
3 Comments
 
LVL 32

Expert Comment

by:jhance
Comment Utility
wcscpy(tag, L"haha");
0
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
Comment Utility
Just to explain a bit.  The string "haha" is an ANSI string under all circumstances.  To make it a UNICODE string you must use the "L" macro to tell the compiler to make a UNICODE string here.  Hence:

wcscpy(tag, L"haha");

is what you want.  Another approach is to use the "T" or "TEXT" macro like:

wcscpy(tag, T("haha"));
or
wcscpy(tag, TEXT("haha"));

but in this case I'd recommend "L" since the wcscpy function ALWAYS takes UNICODE and "T" is a conditional based on whether the build is UNICODE or not.

If you use the conditional string copy function tcscpy() you should use "T" to ensure that you get UNICODE when you need it and ANSI when you need that.
0
 

Author Comment

by:hoooi
Comment Utility
Awesome!!! And thanks for the explanation!
Unicode is really new to me.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Powershell based monitoring system 2 126
ODBC Connection Logging, ADO.NET 6 49
fizzArray2 challenge 1 55
mapBully challenge 6 88
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now