如何在Visual Studio中基于字符串比较设置条件断点?

Kit*_*sto 15 c++ breakpoints string-comparison conditional-breakpoint visual-studio-2012

这是我多年来不时尝试过的,而且从未成功过.我只想根据字符串相等性为Visual C++ 2012设置条件断点.我想测试的变量是

string test;
Run Code Online (Sandbox Code Playgroud)

我试过了

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.
Run Code Online (Sandbox Code Playgroud)

rri*_*wer 5

对于在 Visual Studio 中使用,这已在此处回答。特别是OBWANDO的回答中提供的字符串可以用来设置断点条件。但是请注意,它有点笨拙。即使调试器已停止,当断点被击中时,您也会收到一条警告消息。它似乎不会造成任何伤害。