英文:
How do I find the location of a "vector subscript out of range" error? C++ Visual Studio
问题
我对编程还相当新。我知道什么是“vector subscript out of range”的意思,以及它是如何发生的以及如何修复它。但是我的代码中有很多很多向量,经常出现这个错误。但当出现这个错误时,我总是会看到这个大家都知道的错误框。上面写着“点击重试以调试应用程序”。当我点击它时,它会将我带到“vector”文件中的第1731行。但我该如何找到我代码中创建此错误的地方(行或文件)?
我尝试使用VisualStudio中的调试导航来前后移动以找到我的代码。但这并没有起作用。提前感谢您的帮助。
英文:
I am quite new to coding. I know what "vector subscript out of range" means, how it occures and how to fix it. But I have many many vectors in my code and often get this error. But when this error hits I always get this error box you all know. And it says "Hit retry to debug your application". And when I click it it brings me to line 1731 in the "vector" file. But how do I get to the point (the line or the file) in my code, where I created this error???
I tried using the Debug-Navigation in VisualStudio to move back and forth to get to my code. But this doesn't work. Thanks for your help in advance.
答案1
得分: 1
你应该能够从调用堆栈中找到有问题的地方。在那里,您可以通过双击相应的行上下移动堆栈,并检查 Autos 和 Locals 调试窗口 (https://learn.microsoft.com/en-us/visualstudio/debugger/autos-and-locals-windows?view=vs-2022)。
您可能遇到的问题是您进入调试器的时间太晚,异常未被处理(没有 try/catch 块能够处理它,所以被 C++ 基础结构捕获)。检查 Debug->Windows->Exception Settings 窗口,并设置在抛出异常时中断异常(而不是未处理时)。
英文:
You should be able to find the problematic place from the call stack. There you can go up and down the stack by double-clicking the corresponding line and check the Autos and Locals debugging windows (https://learn.microsoft.com/en-us/visualstudio/debugger/autos-and-locals-windows?view=vs-2022).
The problem you might have is that you are getting into the debugger too late, when the exception is unhandled (there were no try/catch blocks able to handle this, so it was caught by the C++ infrastructure). Check Debug->Windows->Exception Settings window and set the exception you get to break when the exception is thrown (not unhandled).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论