[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

wcscpy question

Posted on 2002-04-25
3
Medium Priority
?
609 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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

649 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