C++ 如何在VisualStudio中基于字符串比较设置条件断点?
这是我多年来不时尝试的事情,但从未完全成功。我只想为基于字符串相等的Visual C++ 2012设置条件断点。我要测试的变量是C++ 如何在VisualStudio中基于字符串比较设置条件断点?,c++,visual-studio-2012,breakpoints,string-comparison,conditional-breakpoint,C++,Visual Studio 2012,Breakpoints,String Comparison,Conditional Breakpoint,这是我多年来不时尝试的事情,但从未完全成功。我只想为基于字符串相等的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 "=="
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.
您可以使用以下便携且简单的方式:
if (!test.compare("foo")) {
int dummy = 0; // any statement, put breakpoint here
}
对于在VisualStudio中使用,已经回答了这个问题。特别是,OBWANDO答案中提供的字符串可用于设置断点条件。然而,请注意,它有点笨拙。即使调试器已停止,当断点被命中时,您也会收到一条警告消息。它似乎没有造成任何伤害。谢谢,但我正在寻找一种方法,在不修改源代码的情况下设置断点条件。您可以随时尝试测试[0]=''是的,该帖子回答了我的问题,OBWANDO的解决方案也非常适合我。谢谢你指出这一点。