Question

This is something I have tried from time to time over the years and never quite succeeded. I just want to set a conditional break point for Visual C++ 2012 based on string equality. The variable I want to test is

string test;

I tried

test == "foo"
=> The breakpoint cannot be set. no operator "==" matches these operands

test == string("foo")
=> The breakpoint cannot be set. no operator "==" matches these operands

test.compare("foo") == 0
=> The breakpoint cannot be set. This expression has side effects and will not be evaluated.

strcmp(test.c_str(), "foo") == 0
=> The breakpoint cannot be set. This expression has side effects and will not be evaluated.
Était-ce utile?

La solution

For use in Visual Studio, this has been answered here. In particular, the string provided in OBWANDO's answer can be used to set the break point condition. Note, however, that it is a bit klugy. You will receive a warning message when the breakpoint is hit even though the debugger has stopped. It doesn't appear to cause any harm.

Autres conseils

You can use the following portable and simple way:

if (!test.compare("foo")) {
    int dummy = 0; // any statement, put breakpoint here
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top