A few things to consider before actually answering the question. First of all, I hope you are aware that string is not an actual type, it is just a representation of array of characters. In high-level programming you are not shown what the data is like underground, so these types of "
string
" or other similar come into action. But each of the framework has built-in functions to find out more.
Now the code that you've shown, is more like C# type (
client.GetResponse()
? That is more like an object from C# being called there; based on the naming convention, may be wrong). But, in C++ a string can be compared to another string using
==
operator. What happens is that the
strings are compared using std::compare
[^] to determine whether both are same or not and returns a value indicating true or false. (
String is not an actual type!)
Your code, I have tested and works just perfect. I tried the following code,
#include <iostream>
#include <string>
int main()
{
std::string webresponse = "5accdd72bb566079faf459cbad0934c5";
std::string secondStr = "5accdd72bb566079faf459cbad0934c5";
if(webresponse == "5accdd72bb566079faf459cbad0934c5" &&
webresponse == secondStr) { std::cout << "Equal";
} else {
std::cout << "Not equal";
}
return 0;
}
You can test it right here,
http://cpp.sh/8rdi[
^]
Now the thing that I wanted to point out is that are you sure it doesn't work? I am sure C# would also work in the same way if that is a C# snippet. However, the answer is inpired by PIEBALDconsult's comment to your question, the actual answer is what he wrote there. :-)