Write a program to copy contents of one file to another using file names passed as the command line arguments.
Answers
Answered by
3
I am writing function only in C++
Header files needed are <fsteram.h>
(<iostream.h> is optional because it is base for <fstream.h>, so all functions of former are present in later)
void copy_file(char* Source, char* Destination)
{
ofstream filein(Source, ios::in);
ifstream fileout(Destination, ios::out);
char ch;. //for char to char transfer
if( (!filein)|| (!fileout))
{ cerr<<"Problem opening files!!!";
return;}
while(!filein.eof())
{
filein.get(ch);
fileout.put(ch);
}.
filein.close();
fileout.close();
}
If you want word to word transfer then use >> and <<. operators and if you want line to line transfer use getline() and write().
Header files needed are <fsteram.h>
(<iostream.h> is optional because it is base for <fstream.h>, so all functions of former are present in later)
void copy_file(char* Source, char* Destination)
{
ofstream filein(Source, ios::in);
ifstream fileout(Destination, ios::out);
char ch;. //for char to char transfer
if( (!filein)|| (!fileout))
{ cerr<<"Problem opening files!!!";
return;}
while(!filein.eof())
{
filein.get(ch);
fileout.put(ch);
}.
filein.close();
fileout.close();
}
If you want word to word transfer then use >> and <<. operators and if you want line to line transfer use getline() and write().
Similar questions