enter code here
void fileCopy( const char * targetFilePath, const char * toPlace ){
FILE * istream, * ostream; //
if(( istream = fopen( targetFilePath, "r" )) == NULL ){
printf("文件不存在!");
exit( 0 );
}
ostream = fopen( toPlace, "w");
char ch;
while( (ch=fgetc(istream)) != EOF ){
cout<<ch<<" ";
fputc( ch, ostream );
}
fclose( ostream );
}
void main( ){
// const char * from = "D://a.jpg";
// const char * to = "D://b.jpg";
const char * from = "D://data.txt";
const char * to = "D://b.txt";
fileCopy( from, to );
cout<<"完成!"<<endl;
}
為什麼復制txt文件讀取沒問題,但是復制圖片文件有問題,望大神求解?
圖片一般是二進制的,用fread/fwrite接口,並用二進制讀寫模式就可以了。fgetc/fputc更多的是處理文本的。