Question
Using C++: Write the definition of a function named fscopy that does a line-by-line copy from one stream to another. This function can be safely
Using C++:
Write the definition of a function named fscopy that does a line-by-line copy from one stream to another. This function can be safely passed two fstream objects, one opened for reading, the other for writing. Assume both files are opened successfully. In addition, it gets a bool argument that is true if the output lines are to be numbered, and another argument , an int that specifies line-spacing in the output. The prototype of the function is as follows.
int fscopy(istream &fsin, ostream &fsout, bool numbered, int spacing);
Assume that the input source is a text file. The function fscopy copies, line by line, the entire content of the data source associated with the first argument to the data target associated with the second argument. It returns the number of lines read in. If the third parameter, the numbered is true, every line that is output is preceded by a 6-position field holding the line number (an integer) followed by a space and then the actual line. If the last argument, the spacing is 2 or more, it specifies the line spacing: for example, it is 3, there are two blank lines output after each line printed. These blank lines are NOT numbered. The following example show that the input file is open and fscopy(fsin, fsout, true, 2) is called to generate the output file. The fscopy() returns 3 in this example.
Input file:
Love all, trust a few, do wrong to none.
Output file:
1 Love all, 2 trust a few, 3 do wrong to none.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started