C 實現複製任意檔案並顯示完成百分比

2021-06-22 22:06:59 字數 1000 閱讀 2723

使用c++ 實現複製檔案,   就要涉及到檔案讀寫操作 主要涉及到c++中兩個類:ifstream(輸入檔案流)ofstream(輸出檔案流),這裡輸入輸出是相對於記憶體而言。

// copy_file.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include#includeusing namespace std;

const int buff_size=1024;

int _tmain(int argc, _tchar* argv)

if (!out_file_stream)

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

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

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

while(!input_file_stream.eof())

; d_read_length+=buff_size;

input_file_stream.read(szbuf, sizeof(char) * buff_size);

if (input_file_stream.bad())

if(i_count%10240==0)

out_file_stream.write(szbuf, sizeof(char) * buff_size);

} input_file_stream.close();

out_file_stream.close();

if (i_percent!=100)

system("pause");

return 0;

}

測試結果如下:

使用protobuf實現任意檔案的傳輸

可以使用proto中的bytes資料型別,將乙個檔案寫入到bytes欄位,然後傳輸,收到資料後,重新抽取bytes,組裝成檔案 syntax proto3 import sensor.proto message framepackage message filepackage message fil...

php實現任意文字檔案的模板替換

php的模板替換功能很強大,不僅僅可以用於網頁,實際上可以用於任何文字檔案的模板替換。因此對於一些 的自動生成需求來說,php的模板替換是乙個很強大的功能。php 執行乙個檔案時,在之外的內容會原封不動地輸出,內部的內容會動態執行。再配合作業系統的重定向命令,可以很方便地將替換後的結果寫入檔案。張三...

C 複製檔案時候顯示進度

using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.linq using system.text u...