MFC 實現檔案的Copy功能

2021-09-14 03:55:35 字數 1383 閱讀 7073

const int buff_size = 10240 + 256 + 4 + 4 ;

void ctestdlg::my_readfile(const char *filepath)

ifstream input_file_stream;

input_file_stream.open(filepath, std::ios::binary);// 以輸入流開啟檔案

if (!input_file_stream)

input_file_stream.seekg(0, ios::end);//將檔案指標移動至末尾

int d_file_length = input_file_stream.tellg();// 獲取檔案長度

input_file_stream.seekg(0, ios::beg);//將檔案指標移到至開始

char *totalsendpacket = new char[buff_size];

char szbuf[10240];

char filename[256] = ;

//從檔案路徑中提取檔案名字

int i = 0;

char filename[256] = ;

const char *ptoslant = filepath;

const char *ptmptoslant = ptoslant;

while ((ptmptoslant = strstr(ptoslant, "\\")) != null)ptoslant = ptmptoslant + 1;

while (filename[i++] = *ptoslant++);

remove(filename);//為了測試方便,每次刪除檔案如果存在

while (!input_file_stream.eof())

//將資訊拷貝到總字串處

memcpy(totalsendpacket, szbuf, 10240);

memcpy(totalsendpacket + 10240, filename, 256);

memcpy(totalsendpacket + 10240 + 256, &realreadbytes, sizeof(int));

my_writefile(totalsendpacket);

} delete totalsendpacket;

messagebox("send over!");

}int ctestdlg::my_writefile(const char *sct)

out_file_stream.write(szbuf, realreadbyes);

out_file_stream.close();

return 0;

}

Java 實現copy的功能

其實看標題大家不要以為非常的難或者高深,其實我只是按照copy的原理實現,其實就io流的操作,先前在學習io流的時候比較抗拒,感覺繁瑣而且難以理解,但是今天重新學習了一次,感覺很有意思,因為我們在所有的程式應用都離不開輸入輸出,後面我會整理出乙個關於我自己對io操作的理解的,希望同大家一起學習,那現...

MFC實現檔案複製刪除功能

用mfc實現指定資料夾下所有檔案的複製 包括含有子資料夾 刪除指定資料夾下所有檔案功能 include include include using namespace std void mycopydirectory cstring source,cstring target else void m...

MFC實現列印功能

使用cprintdialog類的建構函式 cprintdialog bool bprintsetuponly,true for print setup,false for print dialog dword dwflags pd allpages pd usedevmodecopies pd no...