简体   繁体   English

如何找到“向量下标超出范围”错误的位置? C++ 视觉工作室

[英]How do I find the location of a "vector subscript out of range" error? C++ Visual Studio

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.当我单击它时,它会将我带到“矢量”文件中的第 1731 行。 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.我尝试使用 VisualStudio 中的调试导航来回移动以获取我的代码。 But this doesn't work.但这不起作用。 Thanks for your help in advance.提前感谢您的帮助。

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 ).在那里你可以 go 通过双击相应的行并检查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).您可能遇到的问题是您进入调试器太晚了,当异常未被处理时(没有 try/catch 块能够处理这个,所以它被 C++ 基础设施捕获)。 Check Debug->Windows->Exception Settings window and set the exception you get to break when the exception is thrown (not unhandled).检查Debug->Windows->Exception Settings window 并设置在抛出异常(不是未处理)时中断的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM