Thursday, May 29, 2008

Copying files in C++

Long time no blogging ! :)

I wanted to copy the contents of one file to another file in C++ in my project and was looking for the most easiest and convenient way of doing it on the net. Finally zeroed in on the following way (found it on some other blog):

#include <fstream>

using namespace std;

int main()
{
    ifstream inFile("input.txt");
    ofstream outFile("output.txt");

    outFile << inFile.rdbuf();

    return 1;
}

Google