这是我多年来不时尝试过的,而且从未成功过。我只想根据字符串相等性为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.
答案 0 :(得分:3)
要在Visual Studio中使用,已经回答here。特别是,OBWANDO答案中提供的字符串可用于设置断点条件。但请注意,它有点麻烦。即使调试器已停止,您也会在遇到断点时收到警告消息。它似乎没有造成任何伤害。
答案 1 :(得分:-2)
您可以使用以下便携且简单的方式:
if (!test.compare("foo")) {
int dummy = 0; // any statement, put breakpoint here
}