CREATE A FUNCTION

How can one create a function whose input is 2 strings ( representing an existing filename and a new filename respectively) And the function to be able to creat the new file which is an exact replica of the existing file?
How to fix this help please!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<string>
using namespace std;

int main()
{
    string m1;
    string m2;

    cout << "Enter a file to be opened for input: ";
    string  inFilename;
    cin >> inFilename;

    ifstream inFile;
    inFile.open(inFilename.c_str());

     inFile >> m1;
     inFile >> m2;

    if(inFile.fail())            //file does not exist
    {
        cout << inFilename << " does not exist.  Please check it is in the appropriate folder.\n"; }

   for (inFile.new())       // Create new file
    {
         cout << inFilename << "New file that is an exact replica of the existing file.\n";
    }
        system("PAUSE");
        return 0;
}
1
2
3
4
5
6
7
void duplicateFile (string input, string newFile)
{
    ifstream  src(input.c_str());
    ofstream  dst(newFile.c_str());

    dst << src.rdbuf();
}
Last edited on
what is src? and dst?
src is the declaration for a new input stream (ifstream).

dst is the declaration for a new output stream (ofstream).

The streams hold the data that's written to their respective files.
Last edited on
Thanks
but how can we make the whole program run?
do u mind writting down the whole program, like add to what i had before
Topic archived. No new replies allowed.