I can make this program to copy diverse format wihout losts.

C:\\animal.exe to D:\\animal.exe
(The File location write in locale)

#include <iostream>
#include <fstream>
using namespace std;
int main ()
    char data[50];        
   char inputFile [100];      
    cout <<"Insert inputFilePatch :"<<endl; 
    cin >> inputFile;    
    ifstream inputFilePatch;           
    if(!inputFilePatch) {   
    cout << "Wrong Location!!!\n";
    return 1;
    char outputFile[100];  
    cout<<"Insert outputFilePatch  "<<endl; 
    cin >> outputFile;
    ofstream outputFilePatch;
        outputFilePatch<<data<< endl;
   return 0; 

This is exactly just for .txt files!
What to change to work these?

Recommended Answers

All 4 Replies

I really don't know what you mean, but you might want to open the files in binary mode...

If you are trying to write that code for MS-Windows then you can use win32 api CopyFile() function. Otherwise open the input and output files in binary mode, not the default text mode. On *nix it doesn't matter because they are both the same, but on MS-Windows there is a difference.

the easiest, least error-prone and the fastest way to copy an entire stream is this:
output_stream << input_stream.rdbuf() ;. if you are writing a utility like this, error messages are conventionally sent to cerr (not cout).

#include <iostream>
#include <fstream>
using namespace std ;

int main( int argc, char** argv )
  if( argc != 3 ) 
    cout << "usage: " << argv[0]  << "<srce file>  <dest file>" ;
    return 1 ;
  ifstream srce( argv[1], ios::binary ) ;
  if( !srce )
    cerr << "could not open " << argv[1] << " for reading\n" ;
    return 2 ;
  ofstream dest( argv[2], ios::binary ) ;
  if( !dest )
    cerr << "could not open " << argv[2] << " for writing\n" ;
    return 3 ;
  dest << srce.rdbuf() ;
  if( !dest )
    cerr << "error while copying\n" ;
    return 4 ;

Thanks for your help!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.