?
Solved

wcscpy question

Posted on 2002-04-25
3
Medium Priority
?
605 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

764 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