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.

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.

LANGUAGE: C++

CHALLENGE:

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.

SOLUTION:



void fscopy(fstream &input , fstream &output){
    string buffer;

    while(!input.eof()){
        getline(input,buffer);
        output << buffer << "\n";
    }

    input.close();
    output.close();
}

Add comment