Solved

wcscpy question

Posted on 2002-04-25
3
599 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
ID: 6969369
wcscpy(tag, L"haha");
0
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 6969392
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
ID: 6969417
Awesome!!! And thanks for the explanation!
Unicode is really new to me.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

864 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

16 Experts available now in Live!

Get 1:1 Help Now