Original: Http://blog.csdn.net/cadcisdhht/archive/2010/06/05/5649681.aspx
When debugging programs with Visual Studio, we often need to add breakpoints based on values. For example, when i = = 2 o'clock interrupt run, we can add the following breakpoint:
Sometimes, we need to add a breakpoint based on the contents of the string. For example, we are debugging the following code:
void Cvsdebugtricksdlg::onbnclickedbutton1 () {char* string; for (int i = 0; i < 5; ++i) {string = GetString (i); TRACE (string); } char* cvsdebugtricksdlg::getstring (int number) {switch (number) {case 0:return ' Zero '; case 1:return ' one '; case 2 : Return "two"; Default:return "Other"; } }
We hope that when you run to trace (string), you can break the string if it is "two". If we were to add a breakpoint to a value, add the following breakpoint:
When we run the above code, we find that even if the contents of string "Two", the run is not interrupted. This is because the = = operator compares the address of the two string rather than the content, so the above breakpoint does not meet our needs.
Visual Studio takes into account that programmers often add breakpoints based on the contents of strings, so special support for strings is added to this feature of adding breakpoints. When we add breakpoints based on string content, we can use functions like strcmp to set breakpoints.
So in the example above, we can use the STRCMP function to add the following breakpoint:
The string functions supported in the Add Breakpoints feature in Visual Studio are: strlen, wcslen, Strnlen, Wcsnlen, strcmp, wcscmp, _stricmp, _wcsicmp, strncmp, wcsncmp, _ STRNICMP, _wcsnicmp, STRCHR, WCSCHR, Strstr, Wcsstr.