-
July 1st, 2012, 08:46 PM
#1
trouble with strcmp
so after trying awhile to compare a const char* to a string, I read that I'm supposed to compare using the strcmp method. But I'm still not getting a correct comparison to a string. While debugging, my text values look fine so I'm stumped. I'm trying to compare values in my std::map like so -
Code:
for(std::map<Vector3DInt32,const char*>::iterator i = polys.begin(); i != polys.end(); i++) {
if(strcmp((*i).second,"Neighbor") == 0) mywindow->appendText("[colour='FFFF0000']");
else mywindow->appendText("[colour='FFFFFFFF']");
mywindow->appendText("{ ");
mywindow->appendText(Ogre::StringConverter::toString(Vector3((*i).first.getX(),(*i).first.getY(),(*i).first.getZ())));
mywindow->appendText(" }, ");
}
I also tried using std::string and then comparing using
if((*i).second.compare("Neighbor") == 0)
but that is failing also...
P.S. where is the code tag button?
Last edited by Marc G; July 2nd, 2012 at 01:30 AM.
Reason: Fixed code tags
-
July 1st, 2012, 09:41 PM
#2
Re: trouble with strcmp
How is it failing?
By the way: you got the code tags almost right except that you should close with [/code].
-
July 1st, 2012, 10:18 PM
#3
Re: trouble with strcmp
Originally Posted by drwbns
so after trying awhile to compare a const char* to a string, I read that I'm supposed to compare using the strcmp method. But I'm still not getting a correct comparison to a string.
The comparison is correct. Are you saying that strcmp() or std::string::compare has bugs? Obviously, what's behind that variable is not the string "Neighbor", as you claim it to be, since there is no chance that both of these functions have bugs comparing simple strings (if that were the case, thousands of programmers would have reported it).
While debugging, my text values look fine so I'm stumped.
There is a difference between how it looks in the debugger and what that value really is. If you took the time to output each character in a loop, or you did a more thorough inspection using the memory window of the debugger, you will see that the string is not "Neighbor", but possibly a string that contains control characters or spaces that are not visible under ordinary circumstances.
Also, after 97 posts, you don't know how to properly use code tags?
Regards,
Paul McKenzie
Last edited by Paul McKenzie; July 1st, 2012 at 10:23 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|