std::wstring string0 = L"blah";
std::wstring string1 = L"blah";
if(string0 == string1)
{
// do stuff...
}
[SOLVED] comparing widestrings
Hey Gamedev :),
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]
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).
(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:
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! ;)
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! ;)
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
Popular Topics
Advertisement