How to set conditional breakpoint based on string comparison in Visual Studio?

Kit Fisto picture Kit Fisto · Feb 21, 2014 · Viewed 26.7k times · Source

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.

Answer

rrirower picture rrirower · Feb 21, 2014

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.