how to create conditional breakpoint with std::string

There is a much easier way in Visual Studio 2010/2012.

To accomplish what you are looking for in ANSI use this:

strcmp(newString._Bx._Ptr,"my value")==0 

And in unicode (if newString were unicode) use this:

wcscmp(newString._Bx._Ptr, L"my value")==0 

There are more things you can do than just a compare, you can read more about it here:

http://blogs.msdn.com/b/habibh/archive/2009/07/07/new-visual-studio-debugger-2010-feature-for-c-c-developers-using-string-functions-in-conditional-breakpoints.aspx


Some searching has failed to turn up any way to do this. Suggested alternatives are to put the test in your code and add a standard breakpoint:

if (myStr == "xyz")
{
    // Set breakpoint here
}

Or to build up your test from individual character comparisons. Even looking at individual characters in the string is a bit dicey; in Visual Studio 2005 I had to dig down into the member variables like

myStr._Bx._Buf[0] == 'x' && myStr._Bx._Buf[1] == 'y' && myStr._Bx._Buf[2] == 'z'

Neither of these approaches is very satisfactory. We should have better access to a ubiquitous feature of the Standard Library.


In VS2017 you can do

strcmp(newString._Mypair._Myval2._Bx._Buf,"myvalue")==0