Hello, I'm almost at the finish line writing this program, but I've fallen at the last hurdle, something I cant get my head around, so any suggestions would be great.
This is a function in a Data class that prints out the data stored in an array.
1 2 3 4 5 6 7 8
|
void Data::toString()
{
cout << _testONE << ":"
<< _testTWO << ":"
<< _testTHREE << ":"
<< _testFOUR << ":"
<< _testFIVE << endl;
}
|
However, the next stage is to print these results to a file instead of the screen.
The problem I have is that I can’t use the ofstream name in that function without declaring it within it. I need to somehow pass this to the function.
I want a function along the lines of this,
1 2 3 4 5 6 7
|
void Data::fileHandling() //int or void?
{
char fileName[30];
cin >> fileName;
ofstream outputFile;
outputFile.open(fileName,ios::app);
}
|
and then the next function called would be void Data::toString() to write the data, and close the file. What would I have to put into the parameters to make this work?
Any help would be much appreciated, thanks.