I'm trying to set a conditional breakpoint for my debug but VS keeps returning me this error:
How can it be so if the operator != is defined for strings?
The variable error is std::string
CodePudding user response:
There are many workarounds you can do, for example a much better way of writing your condition is this:
!errors.empty()
You also have size()
that you can compare against 0, c_str()
that returns a C string which you can test the first element against \0
, etc etc.
As to the reason why your line doesn't work is that most likely the conditional debugger can't resolve the overloaded operator. Perhaps checking against a non-implicitly built string
(ie, error != string{}
) would work better, or using a newer VS version, but really you can see how wasteful that is instead of just simply checking the empty()
function result.
CodePudding user response:
Temporarily adding something like this to your code might do it:
const auto s = string_i_want_to_test_to_see_if_its_empty.c_str ();
and then for the conditional breakpoint, the expression would be:
s [0] != 0;
Put that breakpoint on the line immediately after the one added. Hopefully, in a Debug build, it won't get optimised out. If it does, I'm sure you'll think of a way round it.