2015年1月19日星期一

A simple C++ Program to copy binary file

Just a C++ Test Program


#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
// You have to declare using the file in binary mode.
// Otherwise you will be tarpped in strange problems.
ifstream fin("Hash.exe",ios::binary|ios::in);
ofstream fot("Copy.exe",ios::binary|ios::out);
char ch;
// Check status of input file
if (!fin.good())
{
cout<<"ERROR WHILE OPENNING INPUT FILE"<<endl;
return +1;
}
// Check status of output file
if (!fot.good())
{
cout<<"ERROR WHILE OPENNING OUTPUT FILE"<<endl;
return -1;
}
// You have to be careful not to write a EOF to the output file in the loop below.
// Because when you close the output file, the output file will be attached with a EOF automatically.
if (!fin.eof())
ch=fin.get();
while (!fin.eof())
{
fot.put(ch);
ch=fin.get();
}
fin.close();
fot.close();
system("pause");
return 0;
}
view raw 2013092901.cpp hosted with ❤ by GitHub

没有评论:

发表评论