我得到一个调试断言失败行1662 [英] I get a debuggging assertion failed Line 1662

查看:247
本文介绍了我得到一个调试断言失败行1662的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们能告诉我为什么会得到这个错误。

Can you guys tell me why I get this error.

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

Debug Assertion Failed! Program: C:\Widnows\system32\MSVCP100D.dll File: c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring line:1662

表达式:字符串下标超出范围

Expression: string subscript out of range

关于你的程序如何导致断言
失败,请参见视觉c ++ doccumentation断言。

For more information on how your program can cause an assertion failure, see the visual c++ doccumentation on asserts.

这是我发现导致问题的代码。我的测试用例的学生是30个字符。另外size为10。

Here is the code I found that has been causing the issue. Student for my test case is 30 characters. Also size is 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,' ');

我创建了一个带有字符串的学生,并且被getline函数占用。

I created student with a string and it is occupied by a getline function.

      getline(studentAnswers, student);

也可以告诉我,如果有一种方法让我在这段代码中使用更多的指针?

Also could you guys tell me if there is a way for me to use more pointers in this code?

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


推荐答案

字符串下标超出范围意味着您试图访问不是学生对象的一部分的内存元素。你说你把对学生[11]的呼唤限制在学生[20]。您确定这是在范围内吗?尝试在过程的每个阶段打印出变量,前后都会更改变量的值和每次循环,并查看数据是否是您认为的数据。

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]. 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.

我不知道你想用这个循环做什么,但也许更容易从学生数组中提取你想要的数据,然后将其分配给answer数组。

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.

这篇关于我得到一个调试断言失败行1662的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆