how to create conditional breakpoint with std::string

Eli picture Eli · Nov 16, 2009 · Viewed 54.7k times · Source

Suppose I have this function:

std::string Func1(std::string myString)
{
   //do some string processing 
   std::string newString = Func2(myString)
   return newString;  
}

how do I set a conditional break when newString has a specific value ? (without changing the source)

setting a condition newString == "my value"

didn't work the breakpoints got disabled with an error "overloaded operator not found"

Answer

OBWANDO picture OBWANDO · Mar 4, 2013

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