Hello!
So I'm trying to figure out how to pass a txt file to a function to be written to only. I will not need to read from it. I cannot figure out how to set up the paramters as I keep getting all kind of complicated complier errors and do not know how to decode them. Its a class project for a payroll input and the output needs to all be sent to a .txt file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void printReportHeadings(whatgoeshere? * fileName); //prototype
int main ()
{
ofstream report;
report.open ("report.txt"); //creates and opens output file called Report.txt
printReportHeadings(again what goes in here?); // function call
report.close(); //closes Report.txt file
return 0;
}
void printReportHeadings(ostream &report) // <---are the paramters correct for the function definition?
{
report << "\n Employee Pay Reg Hours Gross Fed Tax SSI Tax Net";
report << "\n Name Rate Ovt Hours Pay State Tax Defr Pay";
report << "\n ========= ===== ========= ======= ======== ======= ======";
}
See my notes after the function proto, call, and definition.
(hopefully the formatting holds using the code tags...first time poster)
I've tried to search for an answer to my problem and haven't been able to come up with a solution yet. Thank you for any help!
for file streaming you should use fstream classes, for output to the file use ofstream and input to the file use ifstream.
ostream and istream is for output and input to and from the screen.
so you should change
ostream to ofstream in the function prototype and definiition
The reason you had trouble is because you put usingnamespace std;after your function prototype, so it didn't know what an "ostream" was at that point. Either way, good luck :)