| micker2g (4) | |||
|
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.
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! | |||
|
Last edited on
|
|||
| Moeljbcp (85) | |||
Er, well, first of all, did you try making your function prototype and your function definition match?
And you'd just call the function by doing printReportHeadings(report); in mainIf you still need help beyond this I can paste the exact code that works, but honestly it's basically just the sum of the changes I listed. | |||
|
Last edited on
|
|||
| vichu8888 (176) | |
|
prototype and function definition both exactly same. so protoype= void printReportHeadings(ostream& report);definition= void printReportHeadings(ostream& report) {} function call is without any type name just variables name and function name so it will be function call= printReportHeadings(report)
| |
|
|
|
| micker2g (4) | |||
|
OK thank you but still not working. Here is the exact stub code I'm trying to run.
Also I will eventually have another funtion writing to this same file within a loop as these are just the file headers. Thanks again! errors: 'ostream' : undeclared identifier 'report' : undeclared identifier 'printReportHeadings' : illegal use of type 'void' | |||
|
|
|||
| vichu8888 (176) | |
|
sorry for the wrong guidance 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
| |
|
|
|
| vichu8888 (176) | |
| and declare your prototype before main and after using namespace std; | |
|
|
|
| micker2g (4) | |
| Thank you! It worked! Very much appreciated, now i can begin writing the rest of it. | |
|
|
|
| Moeljbcp (85) | |
The reason you had trouble is because you put using namespace std; after your function prototype, so it didn't know what an "ostream" was at that point. Either way, good luck :)
| |
|
Last edited on
|
|