我不能循环通过2d for循环 [英] i can't loop through a 2d for-loop
本文介绍了我不能循环通过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).
这篇关于我不能循环通过2d for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文