This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
没有评论:
发表评论