//============================================================================ // Name : HelloWorld.cpp // Author : liuqing // Version : // Copyright : Your copyright notice // Description : C语言操作文件 //复制文件 //============================================================================ #include <iostream> #include <stdio.h> #include <stdlib.h> #include <dirent.h> using namespace std; int main() { //定义文件指针 FILE *fp,*toFp; //定义输出字符 cout << "Reading file...." << endl; //打开文件 if ( ((fp = fopen("f:\\aa.txt","rb")) == NULL)) { cout << "error open file f:\\aa.txt"; } else { if ( (toFp = fopen("F:\\bbmus\\usb.txt","ba+")) == NULL ) { cout << "Write error" << endl; } while (!feof(fp)) { cout << "reading file!"; char ch = fgetc(fp); if (ch != EOF) { fputc(ch,toFp); } } } fclose(fp); fclose(toFp); //关闭文件 return 0; }