Sign in to follow this  

std::string compare question

This topic is 3591 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 I'm getting weird results from a std::string compare function <code> std::string myString = "000400003ABCD"; std::string PrevResponse = "000400003WXYZ"; if (myString.compare(0,4,PrevResponse,0,4) ==0) //works fine {std::cout << "BLOCK MATCH FOUND\n"; if (myString.compare(4,5,PrevResponse,4,5) ==0) //doesn't work {std::cout << "CONTEXT MATCH FOUND\n";} </code> I want to compare the first 4 integers of a code as above and that works. Then I want to compare the last five integers, doesn't work. According to me both function calls should return true but only the first one does. Driving me crazy, must be missing something obvious. Is there some way to see exactly what is being compared? I've tried changing the npos and length to compare but I can't get it working. m0ng00se

Share this post


Link to post
Share on other sites
Never mind.
The code is fine.
It's something to do with the variables I'm loading.
I only hard coded them above as an example.
In my debugger WATCH window the variable values match but I don't get a true result.
I just tested the code above with hard coded variables and it worked.

--> back to the debugger

m0ng00se

Share this post


Link to post
Share on other sites

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