0
我想在兩個函數之間傳遞數組。 _data函數是我的數組。它需要3個參數;數組本身,數組的大小和數組的文件名。所以這個函數應該從輸入文件(.txt)中獲取每個元素並將其放入數組中,這看起來確實沒問題。將數組傳遞到函數
void _data(string dataArray[], int sizeOfArray, ifstream &fin)
{
const int CharBuffer=20;
char linedata[CharBuffer];
ifstream& getline (char* s, streamsize n);
for(int x = 0; x < sizeOfArray; x++)
{
fin.getline(linedata, CharBuffer);
dataArray[x]=linedata;
cout << dataArray[x] << endl;
}
}
ifstream& operator>>(ifstream &fin, ArrayIntStorage &AIS)
{
string acwData[10000];
_data(acwData, 10000, fin);
return fin;
}
但在接下來的部分我需要從我的數組輸出值到一個文本文件,我必須做一個單獨的函數。
所以我的問題是,我如何訪問存儲在上面的函數中的數據在下面的函數?(或任何其他功能)
ofstream& operator<<(ofstream& fout, ArrayIntStorage& AIS)
{
return fout;
}
我需要以不同的方式初始化我的數組功能,包括返回類型?
什麼是ArrayIntStorage和AIS參數?這與你的問題有關嗎? – quamrana 2011-05-01 17:09:01
@quamrana不,這是不同的功能,我仍然需要實現 – Marc 2011-05-01 17:11:31
@Marc:我問,因爲我懷疑'_data'函數應該將其輸入數據寫入'AIS',這將是轉移到「任何其他功能」。 – quamrana 2011-05-01 17:17:33