?
Solved

wcscpy question

Posted on 2002-04-25
3
Medium Priority
?
620 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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Loops Section Overview
Suggested Courses

850 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