Sign in to follow this  

[SOLVED] comparing widestrings

This topic is 3462 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

Hey Gamedev :),
std::wstring string0 = L"blah";
std::wstring string1 = L"blah";

if(string0 == string1)
{
  // do stuff...
}

Apparently the compiler doesn't like this (can't take left-hand with type std::wstring). However, I do need to check if these two strings contain the same characters. I know there's strcmp for normal strings, but what about wide ones? What's the the trick? Regards, /Stijn [Edited by - stenny on June 23, 2008 11:04:09 AM]

Share this post


Link to post
Share on other sites
Post your code, the problem is elsewhere. Comparing wstring objects is just as valid as comparing string objects; something else is causing the error.

(Post the exact error while you're at it, and make sure its the first error).

Share this post


Link to post
Share on other sites
Compiles fine here (as it should)

So either:
1: You're using a crappy compiler
2: Your actual code isn't what you pasted here
3: Something else

We'll need a bit more information to figure out what the problem is in your case, but the code you posted should compile fine.

My test program looks like this:


#include <string>

int main(){
std::wstring string0 = L"blah";
std::wstring string1 = L"blah";

if(string0 == string1)
{
// do stuff...
}
}

Share this post


Link to post
Share on other sites
Ok. Well, I've never really used widestrings, but this time called for it (DirectX). Anyway, I was about to post my own code when I saw your example Spoonbender.

It appears you don't need to include <string> for creating std::wstrings, but including the header is necessary for the operators to work. I guess that solved it.

Anyway, big thanks for the helping out guys! ;)

Share this post


Link to post
Share on other sites

This topic is 3462 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this