Jump to content
  • Advertisement
Sign in to follow this  
servo

Help me...LPCWSTR

This topic is 3906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi you all. i'm very beginner about this problem.... i init: LPWCSTR myStringW = new wchar_t[6]; or maybe LPWCSTR myStringW = L"mytest"; I don't wanna to convert it first to char* or std::string when i code comparing char n error must be in this line : if (myStringW[0] == 'm') or still error in: if (myStringW[0] == "m\0") Why could it happen n what to do to resolve this? Thanx very much.... [Edited by - servo on November 2, 2007 3:21:46 AM]

Share this post


Link to post
Share on other sites
Advertisement
hi servo,

i don't use this very often, but i think you should stick also a L infront of "m" like:

if (myStringW[0] == L'm')

this should make the "m" also wide char...
then you should be able to compare them.

(actually i'm not sure if there should be single or double quotes before and after the m, try both to be sure)

greets,
tgar

Share this post


Link to post
Share on other sites
It's Work....
It's Work..........
It's Work.....................
Thanx very much to you, Thaligar
n for the information,rvdwef


LPCWSTR myWString=L"mytest";
if (myWString[0]==L'm') {
}

Work very fine
Stil i don't wanna use conversion using std or else....
next problem may be this:


LPCWSTR myWString=L"mytest";
char myChar='m';
if (myWString[0]== ???? ) {
}

comparing myWString[0] with myChar, is there any way?

Share this post


Link to post
Share on other sites
Hey,
It happens because myStringW[0] is a 16-bit number (ie. a wchar_t), and your comparing it to 'm' which is an 8-bit number (ie. a char), so the compiler doesn't like it because the two can't be compared (imagine if myString[0] was > 255).

As for the solution, i think Thaligars suggestions will be fine. or you could try typecasting like

if( myString[0] == (wchar_t)'m' ) //i don't even know if you can do this

wchar_t is usually only used when you need to support Unicode characters, so if you don't need to do that then consider just using a standard char array for myString.

hope this helps!

[edit] oh i got way beaten. anyway for your second problem try the typecast thing i suggested above. but instead make it if( myString[0] == (wchar_t)myChar ) and see what happens..

Share this post


Link to post
Share on other sites
You're welcome,

for comparing a char with a wchar you can use the macros which rvdwerf suggested or you can use mbtowc, this converts a char to a wchar.

Your choice, but i think you have to convert the strings.

@supamike:
"if( myString[0] == (wchar_t)'m' )"

i don't know if this will work but the other way around it works, tested already

"((char*)myString)[i * 2] == 'm'"

where i is the index of the wchar to check, so in our example "((char*)myString)[0] == 'm'". And this works because the
wchars are chars with additional code-page or so, so first
8 bit are a char, and the next 8 bit are the code-page.

(if this is wrong, please correct me)

greets,
tgar

Share this post


Link to post
Share on other sites
@Thaligar:
Yeah, i just scribbled down afew test runs on paper and it's good (i cant test real thing cos visual studio uses 16bit chars by default).
But surely just typecasting the char would be simpler? (and safer) This'd just add an extra 0x00 for a blank code-value onto the char, and allow for a direct comparison.

Share this post


Link to post
Share on other sites
All works......
All works...............
All works.......................

LPCWSTR myWString=L"mytext";
char myChar='m';

From Thaligar_____

if ((char)myWString[0 * 2]==myChar) //WORKS VERY FINE
// i don't use : (char*)

From Supamike_____

if (myWString[0]==(wchar_t)a) //WORKS VERY FINE Too


You two are helpful... thanx very much...

Impossible....
Impossible.........
Impossible..............

I do a sensation like this:

if ((char)myWString[0 * 2]==(wchar_t)myChar)
//damn... I don't believe it's works too

Anyway the problem is solved....

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!