How do I test equality with this particular code?

I'm trying to use an equality operator on a particular variable but Visual Studio is letting me know that: "no operator "==" matches these operands".

I'm using Microsoft's cpprest library and this is a snippet from my code:

1
2
3
4
5
6
7
8
9
10
11
if (response.status_code() == status_codes::OK) {
	auto body = response.extract_string();

	json::value obj = json::value::parse(body.get());
	auto type = obj.at(U("type"));

        // Problem starts here
	if (type == "login") {
            //
	}
}		


If I print the variable 'type' using std::wcout, I get the json value I expected, but I can't seem to make any comparison, I'm assuming because the object doesn't support "=="? I'm a little confused.
Last edited on
try wstring::compare

1
2
3
4
5
6
7
8
  std::wstring str(L"value");

  if (str.compare(L"value") == 0) {
    std::cout << "Equal" << std::endl;
  }
  else {
    std::cout << "Not equal" << std::endl;
  }
Jay thanks a lot, that worked. I just had to convert the var type with the function 'as_string()':

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if (response.status_code() == status_codes::OK) {
	auto body = response.extract_string();

	json::value obj = json::value::parse(body.get());
	auto type = obj.at(U("type"));

	std::wstring str = type.as_string();

	if (str.compare(L"login") == 0) {
		std::cout << "Equal" << std::endl;
	}
	else {
		std::cout << "Not Equal " << std::endl;
	}
}
	


Thanks again!
Last edited on
Topic archived. No new replies allowed.