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?
Several things wrong with this code:
Names that begin with an underscore are reserved for the C++ implementation in most circumstances – don’t use them in your own code unless you have read the C++ Standard fairly closely, which I suspect you have not.
Don’t declare standard library functions yourself. This function is declared in
<iostream>so you should #include that header.The use of an array is suspect. As you are obviously using C++ and the standard library, why not use a
vector<string>which you should pass into your function as a reference.