如何找到“vector subscript out of range”错误的位置?C++ Visual Studio

huangapple go评论101阅读模式
英文:

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

你应该能够从调用堆栈中找到有问题的地方。在那里,您可以通过双击相应的行上下移动堆栈,并检查 AutosLocals 调试窗口 (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).

huangapple
  • 本文由 发表于 2023年1月9日 04:52:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75051202.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定