我是學習嵌入式驅動的,覺得有點閑,所以就看了看一些C++等用戶空間的編程方法。編程經驗比較少,看到檔案截斷,有點搞不清楚其使用的場景,是為了節省空間嗎?
uj5u.com熱心網友回復:
不知你說的截斷是什么,從檔案中截取想要的部分吧uj5u.com熱心網友回復:
SetEndOfFileThe SetEndOfFile function moves the end-of-file (EOF) position for the specified file to the current position of the file pointer.
BOOL SetEndOfFile(
HANDLE hFile // handle of file whose EOF is to be set
);
Parameters
hFile
Handle to the file to have its EOF position moved. The file handle must have been created with GENERIC_WRITE access to the file.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
This function can be used to truncate or extend a file. If the file is extended, the contents of the file between the old EOF position and the new position are not defined.
If you called CreateFileMapping to create a file-mapping object for hFile, you must first call UnmapViewOfFile to unmap all views and call CloseHandle to close the file-mapping object before you can call SetEndOfFile.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
See Also
File I/O Overview, File Functions, CloseHandle, CreateFile, CreateFileMapping, UnmapViewOfFile
uj5u.com熱心網友回復:
有點不一樣的樣子,好像基本上是洗掉檔案的后半段。。。我不懂才問的
uj5u.com熱心網友回復:
有點不一樣的樣子,好像基本上是洗掉檔案的后半段。。。我不懂才問的
uj5u.com熱心網友回復:
所以說EOF是一種截斷手段?
uj5u.com熱心網友回復:
https://www.baidu.com/s?wd=SetEndOfFile
uj5u.com熱心網友回復:
洗掉檔案后半段,不過有什么用途啊uj5u.com熱心網友回復:
想洗掉不要的內容恰好全部位于檔案末尾時……uj5u.com熱心網友回復:
比如一個檔案由一些記錄組成,用洗掉標記了一些不用的記錄(沒有真正洗掉),然后檔案太大需要壓縮整理檔案,就把后面有用的記錄挪到前面空的位置(標記為洗掉的記錄位置),最后截斷檔案。uj5u.com熱心網友回復:
截斷檔案就是洗掉檔案中部分資料,比如日志檔案,每天都會增長,但是當資料太大而且時間太久不需要的資料就會被截斷。用來縮減檔案大小轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/17637.html
標籤:C++ 語言
上一篇:常指標和指標常量
