i am trying to pass an array between two functions. The _data function is my array. It takes 3 parameters; the array itself, the size of the array and the file name of the array. So this function should get each element from the input file(.txt) and put it into the array, which it seems to do ok.
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;
}
but in the next part I need to output the values from my array to a text file which I must do in a separate function.
So my question is, how can I access the data stored in the acwData array above in the function below?(or any other function)
ofstream& operator<<(ofstream& fout, ArrayIntStorage& AIS)
{
return fout;
}
do i need to initialize my array function differently to include a return type?
ArrayIntStorage& AISparameter? Is it relevant to your question?_datafunction should write its input data intoAISand that would be the way of transferring it to'any other function'._datafunction to write the data into a parameter such asAIS?AISa parameter of_dataand write, say, anaddmember forArrayIntStoragewhich takeslinedata.