how to create conditional breakpoint with std::string

前端 未结 11 1015
粉色の甜心
粉色の甜心 2020-12-07 12:54

Suppose I have this function:

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


        
11条回答
  •  隐瞒了意图╮
    2020-12-07 13:59

    While I've had to work around this using something similar to Brad's answer (plus using DebugBreak() to break right from the code), sometimes editing/recompiling/re-running a bit of code is either too time consuming or just plain impossible.

    Luckily, it's apparently possible to spelunk into the actual members of the std::string class. One way is mentioned here -- and though he calls out VS2010 specifically, you can still access individual chars manually in earlier versions. So if you're using 2010, you can just use the nice strcmp() functions and the like (more info), but if you're like me and still have 2008 or earlier, you can come up with a raggedy, terrible, but functional alternative by setting a breakpoint conditional something like:

    strVar._Bx._Ptr[0] == 'a' && strVar._Bx._Ptr[1] == 'b' &&
       strVar._Bx._Ptr[2] == 'c'
    

    to break if the first three characters in strVar are "abc". You can keep going with additional chars, of course. Ugly.. but it's saved me a little time just now.

提交回复
热议问题