简体   繁体   English

输入输入时为什么会出现错误? “表达式:字符串下标超出范围”

[英]Why do I get an error when I enter input? “expression: string subscript out of range”

I get an error when I try to enter input for my implementation of a Lorenzo decoding machine: 当我尝试为Lorenzo解码器的实现输入输入时出现错误:

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

Why? 为什么?

also i am loading in a .dat file which has the pin settings in it. 我也在一个.dat文件中加载了其中的引脚设置。

Here's a section where i think the error lies, within my code: 这是我认为错误所在的部分,在我的代码中:

    string chi (string pinSettings, string code, int count)
    {

 if (count = 0)
 {
        chi1 = 0,;
 }

 compare1 = code[0];
 if (chi1 + 351 >= 391)
{
chi1 = 0;
}
compare2 = pinSettings[chi1 +351];

int result = (compare1 - '0') ^ (compare2 - '0');


compare1 = code[1];

if (chi2 + 392 >= 423)
{
    chi2 = 0;
}


chi1 ++;
chi2 ++;

string fPass;
fPass += (result+'0');
fPass += (result2+'0');

return fPass;
    }

    bool mu (string pinSettings, int count)
    {
char compare1;
char compare2;
static int mu61, mu37;

if (count = 0)
{
mu61 = 0, mu37 = 0;
}

if (mu61 + 290 >= 351)
{
mu61 = 0;
}

compare1 = pinSettings[mu61 +290];
int compareInt1 = (compare1 - '0');
mu61++;

if (compareInt1 == 1)
{
    mu37 ++;
    if (mu37 + 253 >= 290)
    {
          mu37 = 0;;
    }
    compare2 = pinSettings[mu37 + 253 - 1];
    int compareInt2 = (compare2 - '0');

    if (compareInt2 == 1)
    {
        return true;
    }
}
else
{
    return false;
}


    }

    string psi (string pinSettings, int count, bool rotate, string code2)
    {
char compare1;
char compare2;
static int psi1, psi2, psi3, psi4, psi5;

if (count == 0)
{
psi1 = 0, psi2 = 0, psi3 = 0, psi4 = 0, psi5 = 0;
}

if (rotate == true)
{
    psi1++;
    psi2++;
}

compare1 = code2[0];
if (psi1  >= 43)
{
psi1 = 0;
}
compare2 = pinSettings[psi1];


int result = (compare1 - '0') ^ (compare2 - '0');


compare1 = code2[1];

if (psi2 + 43 >= 90)
{
    psi2 = 0;

}

compare2 = pinSettings[psi2 + 43];

int result2 = (compare1 - '0') ^ (compare2 - '0');



string fPass;
fPass += (result+'0');
fPass += (result2+'0');

return fPass;
    }

Use a debugger. 使用调试器。 You don't say what platform you are developing on but common ones are Microsoft Visual Studio, Mac OS X and Linux. 您没有说要开发什么平台,但是常见的平台是Microsoft Visual Studio,Mac OS X和Linux。

In Visual Studio run in Debug mode. 在Visual Studio中以调试模式运行。 Set the debug settings to stop on a C++ exception. 设置调试设置以在C ++异常时停止。

In Linux use GDB. 在Linux中使用GDB。 Compile with gcc -ggdb -O0 , run with gdb ./program and enter catch throw then run . gcc -ggdb -O0编译,用gdb ./program运行,输入catch throw然后run

In OS XI forget the exact steps but they are similar to Visual Studio. 在OS XI中,忘记了确切的步骤,但它们与Visual Studio相似。 You can also use GDB from the command line once you've installed the developer tools. 安装开发人员工具后,您也可以从命令行使用GDB。

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

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