我遇到了一个打印出列表向前和向后列表的问题,但是,当我向后打印列表时,列表中的第一个数字是一个随机的数字而不是正确的数字。例如打印列表向后
0 1 2 3 4 5 6 7 8 0
4286398 8 7 6 5 4 3 2 1 0
任何人都可以解释我的代码有什么问题请。
也有人可以告诉我如何将计数器从printList函数传递给名为checkList()的新函数,以便计数器在checkList()中具有与printList()的末尾相同的值。 。
代码:
void printList(int array1[]){
int counter = 0;
int x;
ifstream theFile("list.txt");
while(theFile >> x){
array1[x] = x;
cout << array1[x] << " ";
counter = counter + 1;
}
cout << endl << counter << endl;;
int n = counter;
for(int i = n -1; i >= 0; i--){
cout << array1[i] << " ";
}
它看起来像一个垃圾数量 – 2013-04-23 17:47:52
什么LIST.TXT的内容是什么? – 2013-04-23 17:48:41
它也看起来像你打印你的柜台。为什么不是你已经发布的输出的一部分 – 2013-04-23 17:50:04