int size = getFileSize(path); //Listed below
ifstream fs(path, ios::in);
ofstream os(path2, ios::out);
//Check - both streams are valid
char buff[CHUNK_SIZE]; //512
while (size > CHUNK_SIZE)
{
fs >> buff;
os << buff;
size -= CHUNK_SIZE;
}
char* dataLast = new char[size];
fs>>dataLast;
os<<dataLast;
fs.close();
os.close();
//發現在SO,工作在PATH2精細
int getFileSize(string path)
{
FILE *pFile = NULL;
if (fopen_s(&pFile, path.c_str(), "rb"))
{
return 0;
}
fseek(pFile, 0, SEEK_END);
int Size = ftell(pFile);
fclose(pFile);
return Size;
}
文件已損壞,小於1 KB。 (初始文件爲30Kb); 我不需要建議如何複製文件,我很好奇這個例子有什麼問題。
沒有建議,但用'>>'閱讀是你現在不想的 – P0W
@ P0W非常感謝。 –