我遇到了一個打印出列表向前和向後列表的問題,但是,當我向後打印列表時,列表中的第一個數字是一個隨機的數字而不是正確的數字。例如打印列表向後
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