Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

ISBN: 978-0764535376

More Books

Students also viewed these Databases questions