Mega Code Archive

 
Categories / C++ Tutorial / File Stream
 

Use ifstream and ofstream to copy file

#include <iostream.h> #include <fstream.H> main(void) {        char ch;        ifstream f1("test.txt");        ofstream f2("text1.txt");                if(!f1)            cerr <<"Can't open IN file\n";        if(!f2)            cerr << "Can't open OUT file\n";                while(f1 && f1.get(ch) )            f2.put(ch);        return (0); }