我不能循环通过2d for循环

问题描述:

我在使用for-loop循环使用2d数组时出现问题

我的程序在进行第一次比较后中断了,我无法弄清楚原因。

这是我的代码



I am having a trouble looping through a 2d array using a for-loop
my program breaks after doing first comparison and i can't figure out why.
here is my code

    readData();
    sortData();
    
    cout << ID_EMEI[5][1] << endl;

    for (int r=0; r<20; r++)
    {
        if (ID_EMEI[r][0] == ID)
        {
            if(ID_EMEI[r][1] == EMEI)
            {
                 cout << ID_EMEI[index][0] << "-";
                 cout << "Customer found, you can give them their belongings"<<endl;
                 cout <<"please write a short report about the phone" <<endl;
                 cin >>report;
                 
                 Write(ID, EMEI, report);
            }
        }
    }

唯一一行引起我的注意力是

The only line that catches my eye is
cout << ID_EMEI[index][0] << "-";



为什么你在这里使用 index 而不是 r ?在输入循环之后,index实际上可能会超出数组(在代码提取中没有显示)。


Why are you using index here instead of r? index might in fact stand one beyond the array after your input loop (which is not shown in your code extract).