如何准确找到哪个向量下标超出范围 [英] How to find exactly which vector subscript out of range
问题描述
你好,
我知道什么意思是"矢量下标超出范围",我想我知道如何处理它。但问题是我的应用程序使用了很多std:向量,我不知道如何找到导致问题的那个。任何人都可以帮助我吗?
我是Visual Studio的新手,并且不太了解debuger。我需要帮助。
提前感谢任何支持。
祝你好运
int main()
{
std :: vector< int> vInts;
for(int i = 0; i< 5; i ++)
vInts.push_back(i);
int x = vInts [5]; //这一行创建错误
返回0;
}
在上面的例子中,矢量变量可以使用0到4进行索引。 值5超出有效范围。 运行时应该生成一个对话框,当您正确响应时,它会带您进入违规的源代码行。
确保使用调试库(即/ MDd或/ MTd)构建程序
Hello,
I know what does mean "vector subscript out of range", and I think I know how to deal with it. But the problem is my application use a lot of std:vectors and I have no idea how to find which one causes the problem. Could anyone help me?
I am new in Visual Studio, and don't know debuger very well. I need help.
Thanks in advance fo any support.
Best regards
int main() { std::vector<int> vInts; for(int i = 0; i < 5; i++) vInts.push_back(i); int x = vInts[5]; // this line creates the error return 0; }In the above example, the vector variable can be indexed using 0 to 4. The value 5 is out of the valid range. The runtime should produce a dialog box that, when you respond properly, will then take you to the offending line of source code. Make sure to build your program using the debug libraries (i.e., /MDd or /MTd)
这篇关于如何准确找到哪个向量下标超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!