Write the definition of a function named fscopy. This function can be safely passed two fstream objects, one opened for reading, the other for writing. Assume that the input source is a text file consisting of a sequence of newline character-terminated lines. The function simply 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. No value is returned.

Respuesta :

Question:

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. 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.

Assume that the input source is a text file consisting of a sequence of newline character-terminated lines. The function 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 it the third parameter, the bool 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 int 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.

Answer:

void fscopy(fstream &fsin, fstream &fsout)

{

string s;

getline(fsin, s, '\n');

while (!fsin.fail( ) )

{

fsout << s << endl;

getline(fsin, s, '\n');

}

}

Following are the method to the given question:

Method Explanation:

  • Defining a method "fscopy" that takes two parameters "input, output".
  • Inside the method, a string variable "buffer" is declared.
  • In the next step, a while loop is defined that checks the input's end-of-file condition.
  • Inside the loop, it checks the inputs value not an end-of-file condition.
  • In this, a "getline" method is defined that inputs parameter value, and uses the output that prints buffer value.
  • At the last, it closes the parameter value.

Method:

void fscopy(fstream &input , fstream &output)//defining a method fscopy that takes two parameter  

{

   string buffer;//defining a string variable  

   while(!input.eof())#defining a while loop that checks inputs value not end-of-file condition.

   {

       getline(input,buffer);//using the getline method that inhputs the string value

       output << buffer << "\n";//using the output method that prints buffer value

   }

   input.close();//using close method that close parameter value  

   output.close();//using close method that close parameter value

}

Learn more:

brainly.com/question/14446604