简体   繁体   English

我收到调试断言失败,行1662

[英]I get a debuggging assertion failed Line 1662

Can you guys tell me why I get this error. 你们能告诉我为什么会出现此错误吗?


Debug Assertion Failed! 调试断言失败! Program: C:\\Widnows\\system32\\MSVCP100D.dll File: c:\\program files (x86)\\microsoft visual studio 11.0\\vc\\include\\xstring line:1662 程序:C:\\ Widnows \\ system32 \\ MSVCP100D.dll文件:c:\\ program files(x86)\\ microsoft visual studio 11.0 \\ vc \\ include \\ xstring行:1662

Expression: string subscript out of range 表达式:字符串下标超出范围

For more information on how your program can cause an assertion failure, see the visual c++ doccumentation on asserts. 有关程序如何导致断言失败的更多信息,请参见有关断言的直观c ++文档。

Here is the code I found that has been causing the issue. 这是我发现导致问题的代码。 Student for my test case is 30 characters. 我的测试用例的学生是30个字符。 Also size is 10. 大小也为10。

    for (count = 0; count < size; count++)
    {
              answers[count] = student[11 + (2*count)];
    }

I created size by the following method 用以下方法制作了尺寸

    string examSize;
    fstream questionNumber;
    questionNumber.open("answers.txt", ios ::in);
    getline(questionNumber, examSize);
    int size = stoi(examSize);

I created answers with the following method. 我用以下方法创建了答案。

     vector<char> answers(size,' ');

I created student with a string and it is occupied by a getline function. 我创建了一个带有字符串的学生,它被一个getline函数占用。

      getline(studentAnswers, student);

Also could you guys tell me if there is a way for me to use more pointers in this code? 你们还可以告诉我,是否有办法让我在此代码中使用更多的指针?

As of now I tried this method to check for an overflow in students I still get the same 到目前为止,我尝试了这种方法来检查学生是否溢出,但我仍然得到相同的结果

error 错误

    for (count = 0; count < size; count++)
    {
        cout << student[11 + count];
    }

As the comments suggest, "string subscript out of range" means that you are trying to access an element of memory that is not part of the student object. 正如注释所建议的那样,“字符串下标超出范围”表示您正在尝试访问不属于学生对象的内存元素。 You say you have limited the call to student[11] to student[20]. 您说您已将学生[11]的呼叫限制为学生[20]。 Are you sure this is in range? 您确定这在范围内吗? Try printing out the variables at each stage of the process, before and after statements that change the variable's value and every time around the loop and see if the data is what you think it should be. 尝试在过程的每个阶段,更改变量值的语句之前和之后以及每次循环时打印变量,以查看数据是否符合您的预期。

I'm not sure what you are trying to do with this loop, but maybe it would be easier to extract the data you want out of the student array first, and then assign it to the answer array. 我不确定您要对此循环执行什么操作,但是也许首先从student数组中提取所需的数据,然后将其分配给答案数组会更容易。

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

相关问题 OpenCV Mat :: at 537行断言失败错误 - OpenCV Mat::at line 537 Assertion Failed Error 在C ++中,会弹出“调试断言失败”窗口,并且我得到矢量迭代器不兼容的错误运行时 - In C++, Debug assertion failed window pops up & I get vector iterators incompatible error runtime 断言失败&lt;0 &lt;= i &amp;&amp; i &lt; <int> 未知函数中的vv.size &lt;&gt;&gt;,文件src \\ matrix.cpp,第912行 - Assertion Failed <0 <= i && i < <int>vv.size<>> in unknown function, file src\matrix.cpp, line 912 我收到调试断言失败的错误? - I'm getting an error that the debug assertion failed? 为什么我的调试断言失败? 表达式:列表迭代器不可取消引用 - Why do I get this Debug Assertion Failed? Expression: list iterator not dereferenceable 在我的 TCP_Client 程序中输入用户名后,出现“调试断言失败”错误 - I get a "Debug assertion failed" error after entering the username in my TCP_Client program C ++:调试断言失败,afx.inl行122 - C++: Debug assertion failed, afx.inl line 122 OpenCV错误:断言在cv :: Mat行522中失败 - OpenCV Error: Assertion failed in cv::Mat line 522 OpenCV错误:断言失败,mat.cpp行537 - OpenCV Error: Assertion failed, mat.cpp line 537 Visual C ++查找导致“Debug Assertion failed”的行 - Visual C++ find line causing “Debug Assertion failed”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM