Return To CS 110 Home

Colour Theme   Font Size Options
 
   
   
   
Passing Fstreams

Passing Fstream to Functions


Video Summary: https://youtu.be/bYhc1fp9dLQ


When you try to pass a filestream, such as ifstream, to a function, you need to add the symbol '&' after the word ifstream in the function prototype and definition. An example might look like this:


This is called "passing by reference." You will learn about what this means next week, but for now just know that you NEED to include the '&' in order for passing the filestream to work.

Exercise

For this exercise, create an input and output file, then create a function that takes each fstream as parameters and writes the content of the input file to the output file. The point is to make sure you understand passing the streams, so the contents and names of the file don't matter.

Solution