//テキストファイルをコピーするプログラム #include int getFileSize(FILE* fp) { fseek(fp, 0, SEEK_END); int fsize = ftell(fp); fseek(fp, 0, SEEK_SET); return fsize; } int main() { char* input = "test.txt"; char* output = "out.txt"; //入力ファイルをオープン FILE* fp = fopen(input,"rb"); if(fp==NULL) { printf("inpput file error\n"); return -1; } //出力ァイルをオープン FILE* fpout = fopen(output,"wb"); if(fpout==NULL) { printf("output file open error\n"); return -1; } //ファイルサイズ分のデータを確保 int fsize = getFileSize(fp); char* buff = new char[fsize]; //入力データをバッファにコピー fread(buff, sizeof(char), fsize, fp); fwrite(buff, sizeof(char), fsize, fpout); fclose(fp);////ファイルをクローズ fclose(fpout);//ファイルをクローズ delete[] buff;//バッファを解放 return 0; }