Ecco a grandi linee quello che intendo x acqua calda:
#1
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in ("src", ios::in | ios::binary);
if (in.fail())
{
cout << "error" << endl;
return -1;
}
ofstream out("dst", ios::out | ios::binary);
out << in.rdbuf();
out.close(); in.close();
return 0;
}
#2
#include <iostream>
#include <fstream>
using namespace std;
#define BUFSIZE 1024
int main()
{
char buf[BUFSIZE];
ifstream in ("src", ios::in | ios::binary);
if (!in)
{
cout << "error" << endl;
return -1;
}
ofstream out("dst", ios::out | ios::binary);
while (!in.eof())
{
in.read (buf,BUFSIZE);
out.write (buf,in.gcount());
}
out.close(); in.close();
return 0;
}
#3 (C)
#include <stdio.h>
#define BUFSIZE 1024
int main ()
{
FILE *in,*out;
char buf[BUFSIZE];
size_t n;
if ((in =fopen ("src","rb"))==NULL)
{
printf ("error\n");
return -1;
}
out=fopen ("dst","wb");
while ((n=fread (buf, 1, BUFSIZE, in ))>0)
fwrite (buf, 1, n, out);
fclose (in);fclose(out);
return 0;
}