File Streams
So... one fine morning I awoke with the full code for this program in my
head! You know that something starts to take over your life when you start
to dream about it.
| Dreamapp.cpp |
// INCLUDES
//
//#include bcb only
#include
#include
#include
#pragma hdrstop
// NAME: DreamApp.CPP
// TYPE: C++ SOURCE FILE
// SYNOPSIS: I dreamt of this program!
// DESCRIPTION: copies text files from the
Command line
// EXAMPLES:
// BUGS:
// SEE ALSO:
//---------------------------------------
// Function headers
int Copy(char* from, char* to);
//--------------------------------------- |
|
int main(int argc, char* argv[])
{
// test argc to ensure sufficient args <2
if(argc <3 || argc>4)
{
cout<<"Incorrect number of parameters."<<
endl;
cout << endl << "Press any key
to continue...";
getch();
return 0;
}
Copy(argv[1], argv[2]);
return 1;
}
|
| Note: |
|
|
| function Copy( ) |
//////////////////////
//Function: int Copy(char* from, char* to)
//
//Description: Copies text from one file to
another
//
/////////
|
|
int
Copy(char* from, char* to)
{
ifstream in;
ofstream out;
in.open(from);
if(!in)
{
cout<<"Cannot open file "<
cout << endl << "Press any key
to continue...";
getch();
return 0;
}
out.open(to);
if (!out)
{
cout<<"Cannot open file "<
cout << endl << "Press any key
to continue...";
getch();
return 0;
}
while (!in.eof())
{
out.put(static_cast(in.get()));
}
in.close();
out.close();
cout << endl << "File copied.
Press any key to continue...";
getch();
return 1;
}
|
| Note: |
|
|
|
|