[SOLVED] comparing widestrings

Started by
3 comments, last by Spoonbender 15 years, 10 months ago
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]
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel
Advertisement
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).
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...	}}
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! ;)
What do I expect? A young man's quest to defeat an evil sorceror while discovering the truth of his origins. A plucky youngster attended by her brutish guardian. A powerful artifact which has been broken into a small number of artifactlets distributed around the world.What do I want? Fewer damn cliches. - Sneftel
You need to include the string header to create std::wstrings as well, unless you have a *very* strange compiler.

This topic is closed to new replies.

Advertisement