c++ - MyCopy - C++ Style (Source)
Header
mycopy_cpp.h
#ifndef MYCOPY_CPP_H
#define MYCOPY_CPP_H
void mycopy_cpp( const char *sSrc, const char *sDest );
#endif
Source
mycopy_cpp.cpp
#include "mycopy_cpp.h"
#include <iostream>
#include <fstream>
#define BUFSIZE (1024)
using namespace std;
int main(int argc, char *argv[])
{
if( argc != 3 )
{
cout << "usage: mycopy_cpp src dest" << endl;
return 1;
}
mycopy_cpp( argv[1], argv[2] );
return 0;
}
void mycopy_cpp( const char *sSrc, const char *sDest )
{
char buf[BUFSIZE];
fstream fIn( sSrc, ios::binary|ios::in );
fstream fOut( sDest, ios::binary|ios::out );
cout << "Copying " << sSrc << " to " << sDest << "." << endl;
while( fIn.good() )
{
fIn.read( buf, BUFSIZE );
fOut.write( buf, fIn.gcount() );
}
fIn.close();
fOut.close();
}