#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int
main(int argc, char* argv[])
{
   if(argc == 2) {
      string buffer;
      char buffer2[1024];
      string temp;
      cout << "Please type \"$\" to end this program...\n";
      cout << "\n" << flush;
      cin.getline(buffer2,1023);
      while(cin) {
         temp = buffer2;
         if(temp == "$") break;
         buffer += temp + "\n";
         cin.getline(buffer2,1023);
      }
      fstream fout(argv[1], ios::ate | ios::trunc | ios::out);
      if(!fout.fail()) {
         fout << buffer << flush;
         fout.close();
         cout << endl;
         cout << buffer.size() << " bytes written to file \"" 
              << argv[1] << "\"..." << endl;
      }
      else {
         cout << "unable to open file...\n";
      }
   }
   else {
      cout << "usage: copycon <file>.txt" << endl;
   }
   return 0;
}
