好的,很抱歉地提出另一個這樣的問題。我查看了答案的答案。我得到了圍繞變量nums的錯誤堆棧。是否意味着我在變量nums附近鍵入了一些額外的代碼?我試圖找出它,但我找不到它。我是編碼的小白,所以很抱歉。這裏是我的代碼,我認爲問題在於我的運行時檢查錯誤2
cout << "The numbers on file are:\n " << nums, size;
和我上面的主要read_data調用,但我找不到問題。謝謝!
我的代碼:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
void read_data(int nums[], int size);
int main()
{
const int size = 24;
ifstream dataIn;
int nums[size];
read_data(nums,size);
cout << "The numbers on file are:\n " << nums, size;
system("PAUSE");
return 0;
}
void read_data(int nums[], int size)
{
ifstream dataIn;
dataIn.open("walrus.txt");
if(dataIn.fail())
{
cout << "File does not exist." << endl;
exit(1);
}
int count;
for (count = 0; count < size; count++)
{
dataIn >> nums[size];
}
dataIn.close();
}
問題是什麼? – aschepler