Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having horrible and annoying problems when trying to passstring variables i

ID: 3618068 • Letter: I

Question

I am having horrible and annoying problems when trying to passstring variables into and out of functions. And, more importantly,passing the ifstream and ofstream in and out of functions. I amusing them all as reference parameters, and I just keep gettingerrors.
take the function of the following format:
void iostream(ifstream&, ofstream&) //functionprototype
iostream(infile, outfile) //function call
void iostream(ifstream& infile, ofstream& outfile)//function header/definition start
I also tried using a function call of the type
iostream(ifstream& infile, ofstream& outfile)

The first type of call gives the error: no match for call to'(std::iostream)(std::string&,std::string&)'
The second type of call gives the error: expectedprimary-expression before '&' token
I need to pass the current file stream in between around 10functions for the project for my class. Anyone got any ideas?

Explanation / Answer

Try changing the name of the function from iostream tosomething else since iostream is a class in the std namespace (Ithink) I have no idea why you are using the ampersand operator, ifyou want to pass by reference I suggest using the * operator.
Something like: void iostreamfunc(ifstream*, ofstream*); //functionprototype or even void iostreamfunc(ifstream,ofstream); One of the above should work even though I'm not too familiarwith fstreams.
So when calling, you could using something like iostreamfunc(&infile,&outfile) //for the first or iostreamfunc(infile,outfile) // for the secondprototype.