Question

I am getting this error with my c++ code: http://imageshack.us/photo/my-images/193/vcerror.png/

The only problem is it doesn't point me to where the problem is... I understand the string subscript is out of range but I have no idea where it could be.

I was wondering if there is anyway I am able to find where it is? I have a rough idea so I have put a breakpoint in there but how VC++ does breakpoints is horrible. I step-through but it only shows me the code from the C++ files themselves, not my own code.

So, I step over and the error shows straight away.

How can I track down this problem?

Was it helpful?

Solution

Basically, you need to look at the callstack and have all your symbols setup.

I'm going to take a wild guess and suggest that you may not know how to use the "call stack" window.

In a debug session of your program and no breakpoints set, allow your program to run until it hits the assert dialog. Press "retry" to allow control to be passed to the debugger. Another dialog may pop up to prompt you to "break" or "continue". Select break. You should be broken into the debugger at this point.

Then make sure you can see the call stack and have at least one watch window up.

Debug->Windows->Call Stack.
Debug->Windows->Watch->Watch 1

You can double-click on any item in the call stack window to jump to the exact line of code where execution is expected to return to. (Sometimes the little arrow on the editor window is pointing to the next line of code to run after the previous call returns). Double click on the function line in the call-stack window that is directly below the top call stack line. That's likely std::basic_string::operator. What value is getting passed into this function? If hovering over the variable name doesn't work, add it to the "Watch" window. Also, add a watch for "this" so you can analyze the actual size and capacity of the string.

Double click on the function call in the call-stack below where you are currently at. This should take you to the actual buggy line of code in your program. Add another watch for the string variable and should be able to figure out what went wrong.

The rest is up to you.

I'm assuming this is a standalone EXE project with everything build by the IDE. If it is not, then make sure the PDB files from each binary produced is in the same directory as the corresponding binary. Again, if this is a simple EXE project in Visual Studio, this is automatic. Just to be sure, make sure you "Clean" your build first, then do a complete rebuild. That sometimes fixes debugging kinks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top