26

这是我多年来不时尝试的事情,但从未完全成功。我只想根据字符串相等性为 Visual C++ 2012 设置一个条件断点。我要测试的变量是

string test;

我试过了

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.
4

2 回答 2

5

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

于 2014-02-21T14:11:01.440 回答
-3

您可以使用以下便携且简单的方式:

if (!test.compare("foo")) {
    int dummy = 0; // any statement, put breakpoint here
}
于 2014-02-21T13:43:24.000 回答