Function that reads text file using fstream parameter passed by reference


Homework assignment
Separate existing code into functions
first function must be{
"A function named readInput that returns a string containing the message from a file. The
parameter should be an fstream passed by reference."}

now i know i need to include fstream, but im not sure how too include the fstream into parameters and get the text line all within the same function

i can get the text file via ifstream but no clue where to even start for fstream. any help is appreciated or any resources that i can look at as an example.

basic layout :

void readInput(string Filename,string Text){}

main(){
string Text;

}

but not sure where to go.

first function must be{
"A function named readInput that returns a string containing the message from a file. The
parameter should be an fstream passed by reference."}


void readInput(string Filename,string Text){}

I think it should be more like
 
string readInput(fstream& stream);
A function named readInput that returns a string containing the message from a file.

It should return string and not void.

The parameter should be an fstream passed by reference.


readInput(fstream &reference)

Then from there you perform your read line by line from file.
Last edited on
Topic archived. No new replies allowed.