Greetings, I have a C++ program in which I am trying to print to a file, but using the following commands it isn't working. "payrecord.txt" is created, but blank. I suspect it has to do with my choice of making the displayResults function a "void", but I am not certain. When the code within "displayResults" wasn't a function but instead part of main(), I had only to use "myfile" before the text, but using that in the void() displayResults function results in an error that says:
In function void displayResults()':
myfile' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
Any ideas or advice will be gladly accepted. Thanks very much, relevant (I hope) snips of code follow.
#include<iostream>
#include<fstream>
#include<iomanip>
.
.
.
void displayResults();
.
.
.
int main()
{
ofstream myfile;
myfile.open("payrecord.txt");
for(i=0; i<Count; i++)
{
.
.
.
}
displayResults();
myfile.close();
system("pause");
return 0;
}
.
.
.
void displayResults(void)
{
cout << "Fst Name".....
//changing either of the "cout" statements in this function to myfile
//results in the error message above when compiling
for(j=0; j<Count; j++)
{
cout << First_Name[j].....
}
}